Guest User

Untitled

a guest
Jul 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. ## routes.rb
  2. map.resources :posts do |post|
  3. post.resources :comments
  4. end
  5.  
  6. ## comments controller
  7. def create
  8. @post = Post.find(params[:post_id])
  9. @comment = @post.comments.new(params[:comment])
  10.  
  11. if @comment.save
  12. # ...
  13. else
  14. # ...
  15. end
  16. end
  17.  
  18. ## posts controller
  19. def show
  20. @post = Post.find(...)
  21. @comment = Comment.new
  22. end
  23.  
  24. ## view [html_rails]
  25. <% form_for([@post, @comment]) do |f| %>
  26. ...
  27. <% end %>
Add Comment
Please, Sign In to add comment