Rails 3 Create method using nested resources?
- by user1461119
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.