所以,在我尝试将过滤器添加到视图之前,我已经使用了db中的几行,但是一旦我添加了过滤器逻辑,我就丢失了所有的行。我怀疑它是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>
另外,我已将这些行添加到Distribution模型中:
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]
答案 0 :(得分:0)
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'
}