In rails, I’ve got this checkbox tag, where the checked value should be true if an element is included in post array.
- checked = (params[:comments] && params[:comments][:pictures] && params[:comments][:pictures].include?(comment.id))
=check_box_tag "comments[pictures][]", comment.id, checked
The checked part looks very ugly. How to catch the error if params[:comments] or params[:comments][:pictures] is not set? I tried
- checked = (params[:comments][:pictures].include?(comment.id)) || false
But it does not work.
I would recommend you to install
simple_formand use: