我想列出一个表,其中包含从数据库到表的过滤参数。我为它们分配默认参数,但出现错误:参数数量错误(0 代表 4)
在我的模型中:
class Company < ActiveRecord::Base
scope :filtered, lambda {|count_min, count_max, city, company_status| where(:company_status => company_status, :ap_veh_count => count_min..count_max, :office_adress_city => city, )}
在控制器中:
class LeadsController < ApplicationController
before_filter :confirm_logged_in
def list
params[:sort] ||= "name"
params[:direction] ||= "asc"
params[:company_status] ||= "3"
params[:count_min] ||= "8"
params[:count_max] ||= "20"
params[:city] ||= "Rīga"
@companies = Company.filtered.order(params[:sort] + " " + params[:direction])
end
鉴于:
<% @companies.each_with_index do |company, i| %>
<tr>
<td><%= i + 1 %></td>
<td><%= company.ap_veh_count %></td>
<td><%= link_to company.name, {:action => 'view', :id => company.id} %></td>
<td><%= company.office_adress_city %></td>
<td><%= company.phone %></td>
<td><%= company.company_field %></td>
<td><%= company.email %></td>
<td><%= 'taisīt' %></td>
<td><%= link_to "Atlasīt", {}, :class => 'btn btn-success btn-mini' %></td>
</tr>
<% end %>