[Rails] check box tag binding between controller and the view
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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home