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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:36:53+00:00 2026-06-13T03:36:53+00:00

I am new to RoR. The problem i am facing is that that i

  • 0

I am new to RoR. The problem i am facing is that that i have a few check box and initially when i run my app for the first time i want them all to be selected while for every next time i want it to have the last checked boxes checked. To do this, In my controller i have

 @all_ratings = Movie.all_ratings
 @selected_ratings = []
 if !params[:ratings].nil? 
   params[:ratings].each_key do |key|
     @selected_ratings << key
   end
 elsif
   @selected_ratings = @all_ratings
 end 

While my model looks something like

class Movie < ActiveRecord::Base
  def self.all_ratings
    @all_rating = ['G', 'PG', 'PG-13', 'R']
  end
end  

and the form looks something like this

Include: 
  - @all_ratings.each do |rating|
    = rating
    = check_box_tag "ratings[#{rating}]", 1, rating==@selected_ratings.each{|s_rating|}
  = submit_tag 'Refresh', :id => "ratings_submit"

Now what i am trying to do in the controller is that that i wanted to see if the param is empty if it is then i want to check all the values so i create an instance variable @selected_ratinngs and pass all values of rating into. If i have some values selected from the the checkbox then i save those values in the selected_ratings.

In the view I am planning to use the selected_rating and in the check_box_tag want to compare the selected_rating with rating to see if its already there then the checked parameter is true otherwise.

After such a lenghty description, i want to add that this does not work as planned any ideas.

  • 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-13T03:36:54+00:00Added an answer on June 13, 2026 at 3:36 am

    Include? worked for me instead

    = check_box_tag "ratings[#{rating}]", 1, (@selected_ratings.include? rating)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time I install RoR app based on PostgreSQL database and after run the
I'll preface this with the fact that I'm new to RoR. I have a
So I'm new to Ajax in RoR and having first problem with executing .js.erb
I'm creating my first ROR application. Details: creating new app -> rails new simple_cms
I'm new to ROR, so this could be a very simple problem. I have
We are new to ROR, We have issue in creating Login/Logout process in ROR
I'm new with RoR and I have a controller ( UsersController ) where I
I have an almost new setup of ROR 3.1 here and have already generated
We have an old legacy PHP application. Now I want to write a new
i have a simple cms on ROR 3.2. with this folder scheme: app |controllers

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.