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 9233097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:28:14+00:00 2026-06-18T06:28:14+00:00

How do I implement a check_box_tag with pre-checked boxes which match the values contained

  • 0

How do I implement a check_box_tag with pre-checked boxes which match the values contained in an instance variable @array:

= form_tag xxx_path, :method => :get do 
  - @all_names.each do |name|
    = rating
    = check_box_tag "names[#{name}]", CHECKED IF name in @array
  = submit_tag 'Refresh'

Edit – Controller first:

  def index
    if params[:ratings]
      @filtered_ratings = params[:ratings]
      @movies = Movie.find(:all, :conditions => ["rating IN (?)", @filtered_ratings], :order => params[:sort])
    else
      @movies = Movie.find(:all, :order => params[:sort])   
    end
  end

Now view:

= form_tag movies_path, :method => :get do
  Include: 
  - @all_ratings.each do |rating|
    = rating
    = check_box_tag "ratings[#{rating}]", 1, @filtered_ratings.include?(rating) ? true : false
= submit_tag 'Refresh'
  • 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-18T06:28:15+00:00Added an answer on June 18, 2026 at 6:28 am

    Try this:

    = form_tag xxx_path, :method => :get do 
      - @all_ratings.each do |rating|
        = rating
        = check_box_tag "ratings[#{rating}]", 1, @filtered_ratings.include?(rating) ? true : false
      = submit_tag 'Refresh'
    

    In the controller:

    def index
      @filtered_ratings = params[:ratings] || [] # if no params[:ratings] then assign empty array
      @movies = Movie.order(params[:sort])
      @movies = @movies.where(rating: params[:ratings]) if params[:ratings].present?
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one guide me for the method/approch to implement searching-access-list-boxes-data-as-you-type-in-ms-access-forms with mutiple items
I have an array of NSMutableDictionary objects which are displayed in a master–detail interface
I have a ListView which extends BaseAdapter . I have a data[] array. The
I have a form which contain some radio button and check-boxes . Whenever user
I am trying to implement image as checkbox. I have a list with 2
I am trying to implement a gridview with checkbox column on asp.net (VB). when
This is the feature i want to implement: check a tree node by click
I am trying to implement a check to see if the .NET framework is
Is there a way to implement a CHECK constraint that checks a value against
I'm trying to implement AVL. Here's my insert, balance_tree, check_bf (balance factor), and single

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.