Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails导出xls错误_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 3.2_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails Rails导出xls错误

Ruby on rails Rails导出xls错误,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.2,Ruby On Rails 3.1,大家好,喜欢RAILS的人,我有一个问题,我正试图通过“eExecutive_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_i

大家好,喜欢RAILS的人,我有一个问题,我正试图通过“eExecutive_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 
这是我的局部视图,我使用@list\u策略

 ********************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>

有人能帮我吗?非常感谢所有帮助

我建议您删除
链接
,并将
提交标签
放置在表单中,以便将所有参数发布到控制器方法中


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

请花时间重新格式化您的代码示例,使其可读。这样做会鼓励人们尝试帮助回答你的问题。难以理解的问题会让人们花费额外的时间去理解,从而使他们泄气;我们都是志愿者,我们试图帮助很多人,所以你帮助我们越多,我们就可以帮助你越多。“我有一个问题,我试图导出XLS,但我得到了我所有的结果”没有道理。你没有得到所有的结果吗?zorry my bad,我想通过eExecutive_id导出,但我没有使用正确的参数,这是我的问题,不是通过eExecutive_id搜索,而是通过使用我的条件获取所有值。为什么在查询中使用
LIKE
运算符?这真的是你想要的吗?不,我不想要,这只是我的代码工作的一个例子,在我的代码中应该有一个需要导出的参数。谢谢你的想法,但问题是@results=@list\u policies\u search.find(:all)……我需要在这种情况下通过eExecutive\u id进行搜索,你能检查一下我的代码吗,有人告诉我如果我把这个代码放在@results=@list\u policies\u search.find(:all,:conditions=>['eExecutive\u id LIKE?,@list\u policies]操作数应该包含1列:从策略中选择*,其中(eExecutive\u id LIKE 69,70235151111)和((policies.deleted=0)和((policies.eExecutive\u id IN(76,77,78,79,80)和((policies.state=0)和(policies.deleted=0)))也许有人理解了请有人能帮我?如果你最后的评论需要帮助,那么你的语法是错误的:如果你传递了一个数组,那么你必须在(?)
中将
改为
,而不是
。find(:all,:conditions=>)
您只需使用
。其中(eExecutive\u id:@list\u policies)
   @list_policies = @list_policies_search.paginate(:page => params[:page], :per_page => 10)
 ********************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>
@list_policies = @list_policies_search.paginate(:page => params[:page], :per_page => 10)
@results = @list_policies_search.find(:all)