How can I clean this up using rails 3 features? I have a post that belongs to a group and also a user. The group and user has_many posts. I am using a nested resource
resources :groups do
resources :posts
end
<%= form_for @post, :url => group_posts_path(params[:group_id]) do |f| %>
....
<% end %>
def create
@group = Group.find(1)
@post = @group.posts.build(params[:post])
@post.user_id = current_user.id
respond_to do |format|
if @post.save
.....
end
end
end
Thank you.
Use the
accepts_nested_attributes_formethod in your model.If you’re not familiar with nested forms check out this railscast and the second part for further information.