开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜