xls に保存するときにフォーマットをカスタマイズしようとしています:
- カスタマイズのヘルプが必要です=「日付」+「選択された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
これが私のコントローラーです。ここに、日付 + 選択された 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のみを保存しています。ビューでejecutiveのみを選択したい
format.xls { send_data render_to_string(:partial=>"report_by_ejecutive_xls"), :filename => "#{Date.today}#{@ejecutives.first.name}.xls" }
誰かがこの問題を手伝ってくれませんか?