私は自分のページにFacebookのようなコメントを実装しましたが、ビューを機能させる方法を見つけようとしています。
コメントがどのように機能するかを示すコードは次のとおりです。
コメントコントローラー
class CommentsController < ApplicationController
def create
@micropost = Micropost.find(params[:micropost_id])
@comment = Comment.new(params[:comment])
@comment.micropost = @micropost
@comment.user = current_user
if @comment.save
redirect_to(:back)
else
render 'shared/_comment_form'
end
end
end
コメントフォームビュー
<%= form_for([micropost, @comment]) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :comment_content %>
</div>
<button class="btn" type="submit">
Comment
</button>
<% end %>
そして、私は提出された後にこれらのコメントを最もよく表示する方法を見つけようとしています。これを使用してビューを作成できますか?
comment.html.erb
<%= simple_format(comment.content) %>
<% end %>