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]})%>
精彩评论