Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= form_with(model: [ @article, @article.comments.build ], local: true) do |form| %>
- <p>
- <%= form.label :body %><br>
- <%= form.text_area(:body, {:class => 'form-control'} ) %>
- </p>
- <p>
- <%= form.submit({:class => 'btn btn-success'}) %>
- </p>
- <% end %>
- before_action :authenticate_user!
- def create
- @article = Article.find(params[:article_id])
- @comment = @article.comments.build(comment_params)
- @comment.commenter = current_user
- @comment.save
- redirect_to article_path(@article)
- end
- class Comment < ApplicationRecord
- belongs_to :article
- belongs_to :user
- end
- class User < ApplicationRecord
- has_many :comments, dependent: :destroy
- # Some devise things
- end
- class Comment < ApplicationRecord
- belongs_to :article
- belongs_to :user
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement