无法填充我的视图

发布于 2024-12-21 01:55:12 字数 3522 浏览 2 评论 0原文

因此,在尝试将过滤器添加到视图之前,我已经处理了数据库中的几行,但是一旦添加过滤器逻辑,我就丢失了所有行。我怀疑它是 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]

So, i had this working with several rows from the db before I tried to add the filters to the view but once I added the filter logic, i lost all the rows. I suspect it's thesearch(params[:traits_searchable_search]) because a.) i don't understand it and b.) running that line in the console without the search piece returns the rows I expect.

Here's the controller:

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

and the view:

<%= 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>

Also, I've added these lines to the Distribution model:

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水溶 2024-12-28 01:55:12

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

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'
    }

the problem was in my controller. I needed to make a second object to use for populating the rows based on the first object for searching. like this:

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'
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文