我想定製當我保存爲XLS格式進行下載:錯誤嘗試使用filnename格式
- 我需要幫助定製=「日期」 +「ejecutive選擇」 +「的.xls」
但不工作
我的模型
class Policy < ActiveRecord::Base
unloadable
belongs_to :ejecutive
has_many :policy
def self.search(search)
if search
find(:all, :conditions => ["ejecutive_id = ? ", search.to_i ])
else
find(:all)
end
end
end
class Ejecutive < ActiveRecord::Base
has_many :policies
end
這裏是我的控制LER。 在這裏,我把我的格式,我試圖用日期+ ejecutive定製所選+ .xls的
class PolicyManagement::PolicyController < ApplicationController
def generate_print_ejecutive_comercial
@ejecutives = Ejecutive.find(:all)
@search = Policy.search(params[:search])
@policies = @search.paginate(:page => params[:page], :per_page =>10)
@results= Policy.search(params[:search])
respond_to do |format|
format.html
format.xls { send_data render_to_string(:partial=>"report_by_ejecutive_xls"), :filename => "#{Date.today}#{@ejecutives.name}.xls" }
end
end
這是我的看法
<% form_tag :controller=>"policy_management/policy",:action =>"generate_print_ejecutive_comercial", :method => 'get' do %>
<%= select_tag "search", options_for_select(@ejecutives.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]}) %>
<%= submit_tag "Search", :name => nil %>
<% end %>
Results
<% @policies.each do |policy| %>
<p> <%= policy.num_policy%> </p>
<p> <%= policy.ejecutive.name %> </p>
<p> <%= policy.ejecutive.last_name %> </p>
<% end %>
<%= will_paginate @policies %>
<%= link_to "Export", :controller=>"policy_management/policy",:action=>"generate_print_ejecutive_comercial" ,:format=>"xls",:search => params[:search],:page => params[:page] %>
這是我的,我是出口到局部視圖Excel中
************report_by_ejecutive_xls.**************
<% @results.each do |policy| %>
<%= policy.num_policy%>
<% if !policy.ejecutive.blank? %>
<%= policy.ejecutive.name %><%= policy.ejecutive.lastname1 %><%= policy.ejecutive.lastname2 %>
<% end %>
<% end %>
我試過,但只保存第一ejecutive,我只希望在我看來
012 ejecutive選擇 format.xls { send_data render_to_string(:partial=>"report_by_ejecutive_xls"), :filename => "#{Date.today}#{@ejecutives.first.name}.xls" }
請有人可以幫我解決這個問題嗎?
查看'report_by_ejecutive_xls'視圖會有所幫助。 – spickermann
好男人我編輯它 –