Note that there are some explanatory texts on larger screens.

plurals
  1. PORails exporting xls using link_to format
    primarykey
    data
    text
    <p>Hello everybody who likes RAILS, i have a problem i'm trying to export by "ejecutive_id" to XLS but i'm not doing the correct code, </p> <pre><code> -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) </code></pre> <p>Here is my controller</p> <pre><code> ****PROJECT/APP/CONTROLLER/policy_managment/policy.rb******** class PolicyManagement::PolicyController &lt; 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 =&gt; { :dependent_id =&gt; dependent.id }) list_dependency_dependents.each do |dependency| list_dependencies &lt;&lt; dependency end end policy_ids = [] list_dependencies.each do |dependency| policy_ids &lt;&lt; dependency.policy_id.to_i end end @list_policies_search = @list_policies_search.deleted_is(0) @list_policies = @list_policies_search.paginate(:page =&gt; params[:page], :per_page =&gt; 10) @results = @list_policies_search.find(:all,:conditions=&gt; { :ejecutive_id =&gt; @search_ejecutive }) respond_to do |format| format.html format.xls format.js { render :update do |page| page.replace_html 'table', :partial =&gt; 'table2' end } end end end </code></pre> <p>Here maybe could be the problem,also those are my links where i can export</p> <pre><code> *********HERE IS MY VIEW*********** &lt;% form_remote_tag :url=&gt;{:action=&gt;"generate_print_ejecutive_comercial"},:before=&gt;"load_close('loading_search')",:success=&gt;"load_off('loading_search')" do -%&gt; &lt;label&gt;EJECUTIVES:&lt;/label&gt; &lt;%= select_tag 'search_ejecutive',"&lt;option value=\"\"&gt;Select&lt;/option&gt;"+options_for_select(@list_ejecutives_comision.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]})%&gt; &lt;/span&gt; &lt;label&gt;STATUS :&lt;/label&gt; &lt;%= select_tag "status_id","&lt;option value=\"3\"&gt;ALL&lt;/option&gt;"+options_for_select([["active",0],["cancel",1],["no cancel ",2]],0) %&gt; &lt;/span&gt; &lt;input name="Buscar" value="SEARCH" type="submit" /&gt;&lt;span id="loading_search"&gt;&lt;/span&gt; &lt;% end %&gt; #HERE WITH THOSE LINKS I'M EXPORTING ONLY MY FIRST 10 VALUES &lt;%= link_to("Export Excel","http://localhost:3000/policy_management/policy/generate_print_ejecutive/generate_print_ejecutive_comercial.xls")%&gt; &lt;%= link_to "Export XLS",:controller=&gt;"policy_management/policy",:action=&gt;"generate_print_ejecutive_comercial",:format=&gt;"xls" %&gt; &lt;%= link_to 'PRINT PDF', :controller=&gt;"policy_management/policy",:action=&gt;"generate_print_ejecutive_comercial", :format=&gt;"pdf" %&gt; </code></pre> <p>I'm exporting my partial view and it depends of this </p> <pre><code> @list_policies = @list_policies_search.paginate(:page =&gt; params[:page], :per_page =&gt; 10) </code></pre> <p>Here is my partial view and i'm using @list_policies</p> <pre><code> ********************PARTIAL VIEW THAT I WANT TO EXPORT********* &lt;table&gt; &lt;% @list_policies.each do |policy| %&gt; &lt;tr&gt; &lt;td&gt;&lt;div class="nobreak"&gt;&lt;%= policy.num_policy%&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;div class="nobreak"&gt; &lt;% if !policy.ejecutive.blank? %&gt; &lt;%= policy.ejecutive.name %&gt;&lt;%= policy.ejecutive.lastname1 %&gt;&lt;%= policy.ejecutive.lastname2 %&gt; &lt;% end %&gt;&lt;/div&gt; &lt;/td&gt; &lt;td&gt;&lt;div class="nobreak"&gt;&lt;%= policy.str_state%&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Seems that i need to add some params to my links_to....format.... i don't know what to add Somebody can check this code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload