开发者

link_to passes arguments to checkboxes

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜