开发者

Passing params into a form as pre-selected values in a collection

开发者 https://www.devze.com 2023-02-15 13:56 出处:网络
All, BACKGROUND: Posts have and belong to many Communities. When a user clicks \"Create Post\", certain parameters (params[community_id1,开发者_JS百科 community_id2, etc.]) are passed into the new po

All,

BACKGROUND: Posts have and belong to many Communities. When a user clicks "Create Post", certain parameters (params[community_id1,开发者_JS百科 community_id2, etc.]) are passed into the new post page.

OBJECTIVE: To take these params and have them automatically be attributed to the post - so that if the params being passed are [community_id1, community_id2], the post created by the form will automatically belong to those two communities, without any work needed from the user.

(Ultimately, @post.communities should return the value: [community_id1, community_id2])

Thanks!


do something like this in your controller

@post = Post.new(parmas[:post])

and something like this on your button

<%=link_to 'create post', new_post_path(:post => {:communities => [community_id1, community_id2]})%>
0

精彩评论

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