title: check box tag binding between controller and the view
body: <p>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</p>
  
  <pre><code> @all_ratings = Movie.all_ratings
   @selected_ratings = []
   if !params[:ratings].nil? 
     params[:ratings].each_key do |key|
       @selected_ratings &lt;&lt; key
     end
   elsif
     @selected_ratings = @all_ratings
   end 
  </code></pre>
  
  <p>While my model looks something like</p>
  
  <pre><code>class Movie &lt; ActiveRecord::Base
    def self.all_ratings
      @all_rating = ['G', 'PG', 'PG-13', 'R']
    end
  end  
  </code></pre>
  
  <p>and the form looks something like this</p>
  
  <pre><code>Include: 
    - @all_ratings.each do |rating|
      = rating
      = check_box_tag "ratings[#{rating}]", 1, rating==@selected_ratings.each{|s_rating|}
    = submit_tag 'Refresh', :id =&gt; "ratings_submit"
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>After such a lenghty description, i want to add that this does not work as planned any ideas.</p>