Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:00:43+00:00 2026-06-02T16:00:43+00:00

I want to list a table with filtered parameters from database to the table.

  • 0

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 %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:00:44+00:00Added an answer on June 2, 2026 at 4:00 pm

    Well, you have to pass the params to your filter method at

    @companies = Company.filtered(params[:count_min], params[:count_max], etc.).order...
    

    You may want to define your scope as:

    scope :filtered, lambda { |*args|
      count_min = args.shift || 8
      count_max = args.shift || 20
      city = args.shift || "Rīga"
      company_status = args.shift || 3
    
      where(
        :count_min = count_min,
        :count_max = count_max,
        :city = city,
        :company_status => company_status
      )
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Taking in consideration a table tbl_users , I want to get a list of
I have a table (dump) with transactions, and I want to list the total
I have a long list of data that I want to display in table
I have two tables with list of urls fetched from different sources. I want
I want to list messages that received specific user from other users group by
i want to list files from dev end at tty bettwen 15 and 24...should
I have a list of words that I want to exclude from some query
I want to list top sellers items based on the sales history MySQL table:
**categories** mysql table id|category_name **listings** mysql table id|listing_title|category_id I want to list all categories
I have a list partitioned table on a foreign key. So if I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.