in Rails, with check_box_tag, how do I keep the checkboxes checked after submitting query?
- by Sebastien Paquet
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!