Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <%= form_with(model: [ @article, @article.comments.build ], local: true) do |form| %>
  2. <p>
  3. <%= form.label :body %><br>
  4. <%= form.text_area(:body, {:class => 'form-control'} ) %>
  5. </p>
  6. <p>
  7. <%= form.submit({:class => 'btn btn-success'}) %>
  8. </p>
  9. <% end %>
  10.  
  11. before_action :authenticate_user!
  12. def create
  13. @article = Article.find(params[:article_id])
  14. @comment = @article.comments.build(comment_params)
  15. @comment.commenter = current_user
  16. @comment.save
  17. redirect_to article_path(@article)
  18. end
  19.  
  20. class Comment < ApplicationRecord
  21. belongs_to :article
  22. belongs_to :user
  23. end
  24.  
  25. class User < ApplicationRecord
  26. has_many :comments, dependent: :destroy
  27. # Some devise things
  28. end
  29.  
  30. class Comment < ApplicationRecord
  31. belongs_to :article
  32. belongs_to :user
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement