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) 

        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>Ejecutive:</label>
     <%= select_tag 'search_ejecutive',"<option value=\"\">Seleccione</option>"+options_for_select(@list_ejecutives_comision.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]})%>
   </span>

   <%= hidden_field_tag :order,@order %>
   <%= hidden_field_tag :page,1 %>
   <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>

当我添加这个@results 并在我的部分视图中替换它时,我得到了一切,但我不想要一切,我只想要 ejecutive_id

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

有人可以帮我吗?我将非常感谢所有帮助

4

1 回答 1

0

我建议您删除link_to并将submit_tags 放在表单内,以将所有参数发布到控制器方法中。

因为现在您link_to视图中的链接对于导出您需要的 xls 没有多大意义......

于 2013-09-12T21:17:15.507 回答