I want to list a table with filtered parameters from database to the table. I assign default parameters to them, but I get error: wrong number of arguments (0 for 4)
In my model:
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, )}
In controller:
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
In view:
<% @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 %>
Well, you have to pass the params to your filter method at
You may want to define your scope as:
In order to have defaults for your values. But you still have to pass the params (even if they return nil) so that in case they a set, they would override the defaults.