I successfully learnt how to u开发者_JAVA技巧se has_many :through with checkboxes from this blog.
Now I want to have some of these checkboxes checked, based on arguments passed with link_to.
I tried many different things like...
<%= link_to 'New post', new_post_path, :category_ids => [1, 3] %>
<%= link_to 'New post', new_post_path(:category_ids => [1, 3]) %>
Something like that is a good start, now in your template, where you're adding the checkboxes, just add a small if that checks if there's a category_ids key in params
and you should be good to go: (params[:category_ids] || {}).include?(1)
where 1 is the number you want to check.
精彩评论