Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## routes.rb
- map.resources :posts do |post|
- post.resources :comments
- end
- ## comments controller
- def create
- @post = Post.find(params[:post_id])
- @comment = @post.comments.new(params[:comment])
- if @comment.save
- # ...
- else
- # ...
- end
- end
- ## posts controller
- def show
- @post = Post.find(...)
- @comment = Comment.new
- end
- ## view [html_rails]
- <% form_for([@post, @comment]) do |f| %>
- ...
- <% end %>
Add Comment
Please, Sign In to add comment