我的观点有问题



所以,在我试图将过滤器添加到视图之前,我从数据库中使用了几行,但是一旦我添加了过滤器逻辑,我就失去了所有的行。我怀疑这是search(params[:traits_searchable_search]),因为a.)我不理解它,b.)在没有搜索块的情况下在控制台中运行该行,返回我期望的行。

这是控制器:

class Admin::Distributions::WorkflowsController < Admin::BaseController
  def initialize(*args)
    super
    @active_tab = :distribution
  end
  def index
    @report = Distribution.workflow.search(params[:traits_searchable_search]) #need to find the right params here
    respond_to do |f|
      f.html
      f.csv do
        send_data @report.to_csv, :type => "text/csv", :filename => "distribution_workflow_report.csv"
      end
    end
  end
end

和视图:

<%= render 'admin/distributions/head' %>
<% title 'Workflow' %>

<%= form_for @report, :url => url_for(:controller => params[:controller], :action => params[:action]), :html => {:method => :get} do |f| %>
<div class="opportunity-block yellow">
  <div class="form-block mrl mbm">
    <%= f.label :created_at_gt, "Created at >" %>
    <%= f.text_field :created_at_gt, :class => "js-db-date-picker" %>
  </div>
  <div class="form-block mrl mbm">
    <%= f.label :created_at_lte, "Created at <=" %>
    <%= f.text_field :created_at_lte, :class => "js-db-date-picker" %>
  </div>
  <div class="form-block mrl mbm mtm">
    <%= f.label :status_equal, "Status" %>
    <%= f.select :status_equal, ['delivered', 'follow up', 'manual', ''] %>
  </div>
  <div class="clear"></div>
  <%= submit_tag 'Apply Filter', :class => "input-button dark unit-right mrl" %>
  <div class="clear"></div>
</div>
<table class="standard-grid">
  <tr>
    <th class="first">ID</th>
    <th>Customer</th>
    <th>Customer Email</th>
    <th>Resume URL</th>
    <th>Partner</th>
    <th>Partner Email</th>
    <th>Status</th>
    <th>Assigned To</th>
    <th>Comments</th>
    <th></th>
  </tr>
  <tr>
    <% @report.each do |row| %>
    <td>
      <%= row.owner.id %>
    </td>
    <td>
      <%= row.owner.full_name %>
    </td>
    <td>
      <%= row.owner.email %>
    </td>
    <td>
      <%= row.resume_id%>
    </td>
    <td>
      <%= row.matching_profile.partner.title %>
    </td>
    <td>
      <%= row.matching_profile.partner.email %>
    </td>
    <td>
      <%= select_tag :status, options_for_select(Distribution.select(:status).group(:status).order(:status).map {|d| [d.status, d.status]}, row.status ) %>
    </td>
    <td>
      <%= select_tag :users, options_for_select(User.scoped_by_type('AdminUser').map {|u| [u.display_name, u.id]}) %>
    </td>
    <td>
       <%= text_field :distribution, :comments %>
    </td>
    <td>
      <%= submit_tag "save this record"%>
    </td>
  </tr>
  <% end %>
</table>

此外,我还将这些行添加到分布模型中:

include Traits::Searchable
scope :workflow, :conditions => ["status in (?)", ['delivered', 'follow up', 'manual']]
search_scopes :gt    => [:created_at]
search_scopes :lte   => [:created_at]
search_scopes :equal   => [:status]

问题出在控制器上。我需要创建第二个对象,用于根据第一个对象填充行进行搜索。这样的:

def index
  @search = Distribution.workflow.search(params[:traits_searchable_search]) #need to find the right params here
  #@report.current_user = current_user
  respond_to do |f|
    f.html  {
      @report = @search.paginate(:page => params[:page])
      render :action => 'index'
    }

最新更新