2011-12-14 9 views
1

ビューにフィルタを追加しようとする前に、データベースからいくつかの行を操作していましたが、フィルタロジックを追加するとすべての行が失われました。私はそれがsearch(params[:traits_searchable_search])だと思うので)。)私はそれを理解していませんし、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] 

答えて

0

問題私のコントローラにあった。私は、検索のために最初のオブジェクトに基づいて行を移入するために使用する2番目のオブジェクトを作成する必要がありました。このように:

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' 
    } 
関連する問題