0

RAILS が好きな皆さん、こんにちは。「ejecutive_id」で XLS にエクスポートしようとして問題が発生しましたが、正しいコードを実行していません。

  -I created a select box where i can select all my ejecutives.
  -I created another select box where i can select by status_id.
  -I selected 1 ejecutive for example "Mogan"   (ejecutive_id = 1)
  -I selected 1 status form example "active"   (status_id = 0 )
  -After selecting both select boxes i click on "SEARCH"
  -After doing SEARCH i'm getting my results  (@list_policies this value in my code is before respond format)

これが私のコントローラーです

 ****PROJECT/APP/CONTROLLER/policy_managment/policy.rb********

class PolicyManagement::PolicyController < ApplicationController

 def generate_print_ejecutive_comercial 

        @search_ejecutive = params[:search_ejecutive]
        @search_status = params[:status_id]

        @list_ejecutives_comision = Ejecutive.find(:all)
        @list_policies_search = Policy.deleted_is(0)

        if params[:search_ejecutive].to_i!=0
           @list_policies_search = @list_policies_search.ejecutive_id_is(@search_ejecutive)
        end

        if !params[:status_id].blank?
            if params[:status_id].to_i != 3
                  @list_policies_search = @list_policies_search.state_is(params[:status_id])
            end
        else
            @list_policies_search = @list_policies_search.state_is(0)
        end

        @status_id = params[:status_id]

        if !@search_dependent_dni.blank?
          if @list_dependents.blank?
            @list_dependents = Dependent.id_gt(0)
          end

          @list_dependents = @list_dependents.num_document_is(@search_dependent_dni)

          list_dependencies = []
          @list_dependents.each do |dependent|
                list_dependency_dependents = Dependency.find(:all, :conditions => { :dependent_id => dependent.id })
                list_dependency_dependents.each do |dependency|
                    list_dependencies << dependency
                end
          end

           policy_ids = []
            list_dependencies.each do |dependency|
                policy_ids << dependency.policy_id.to_i
            end

        end

        @list_policies_search = @list_policies_search.deleted_is(0)
        @list_policies = @list_policies_search.paginate(:page => params[:page], :per_page => 10) 
                @results = @list_policies_search.find(:all,:conditions=> { :ejecutive_id => @search_ejecutive }) 

        respond_to do |format|
            format.html
            format.xls
            format.js {
                render :update do |page|
                   page.replace_html 'table', :partial => 'table2'
                end
            }
        end
  end
 end 

ここに問題がある可能性があります。また、これらはエクスポートできるリンクです

     *********HERE IS MY VIEW***********
     <% form_remote_tag :url=>{:action=>"generate_print_ejecutive_comercial"},:before=>"load_close('loading_search')",:success=>"load_off('loading_search')" do -%> 
     <label>EJECUTIVES:</label>
     <%= select_tag 'search_ejecutive',"<option value=\"\">Select</option>"+options_for_select(@list_ejecutives_comision.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]})%>
   </span>
        <label>STATUS :</label>
    <%= select_tag "status_id","<option value=\"3\">ALL</option>"+options_for_select([["active",0],["cancel",1],["no cancel ",2]],0) %>
  </span>

   <input name="Buscar" value="SEARCH" type="submit" /><span id="loading_search"></span>
   <% end %>         


    #HERE WITH THOSE LINKS I'M EXPORTING ONLY MY FIRST 10 VALUES 
   <%= link_to("Export Excel","http://localhost:3000/policy_management/policy/generate_print_ejecutive/generate_print_ejecutive_comercial.xls")%>
   <%= link_to "Export  XLS",:controller=>"policy_management/policy",:action=>"generate_print_ejecutive_comercial",:format=>"xls"  %>
   <%= link_to 'PRINT PDF', :controller=>"policy_management/policy",:action=>"generate_print_ejecutive_comercial", :format=>"pdf" %>

部分ビューをエクスポートしていますが、これに依存しています

   @list_policies = @list_policies_search.paginate(:page => params[:page], :per_page => 10)

これが私の部分的なビューで、@list_policies を使用しています

 ********************PARTIAL VIEW THAT I WANT TO EXPORT*********
 <table>

  <% @list_policies.each do |policy| %>
   <tr>
     <td><div class="nobreak"><%= policy.num_policy%></div></td>
     <td><div class="nobreak">
  <% if !policy.ejecutive.blank? %>
        <%= policy.ejecutive.name %><%= policy.ejecutive.lastname1 %><%= policy.ejecutive.lastname2 %>
  <% end %></div>
    </td> 
    <td><div class="nobreak"><%= policy.str_state%></div></td>
  </tr>
  </table>

links_to....format....にいくつかのパラメータを追加する必要があるようです.何を追加すればよいかわかりません。

4

1 に答える 1