in Rails, with check_box_tag, how do I keep the checkboxes checked after submitting query?

Posted by Sebastien Paquet on Stack Overflow See other posts from Stack Overflow or by Sebastien Paquet
Published on 2012-06-10T20:58:36Z Indexed on 2012/06/10 22:40 UTC
Read the original article Hit count: 224

Ok, I know this is for the Saas course and people have been asking questions related to that as well but i've spent a lot of time trying and reading and I'm stuck. First of all, When you have a model called Movie, is it better to use Ratings as a model and associate them or just keep Ratings in an array floating in space(!). Second, here's what I have now in my controller:

def index

@movies = Movie.where(params[:ratings].present? ? {:rating => (params[:ratings].keys)} :   {}).order(params[:sort])
@sort = params[:sort]
@ratings = Ratings.all

end

Now, I decided to create a Ratings model since I thought It would be better. Here's my view:

= form_tag movies_path, :method => :get do

Include:
- @ratings.each do |rating|
 = rating.rating
 = check_box_tag "ratings[#{rating.rating}]"
= submit_tag "Refresh"

I tried everything that is related to using a conditional ternary inside the checkbox tag ending with " .include?(rating) ? true : "" I tried everything that's supposed to work but it doesn't. I don't want the exact answer, I just need guidance.Thanks in advance!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby