ステータスの更新とコメントデータベーステーブルがあります。
ユーザーには多くのステータス更新があり、ステータス更新には多くのコメントがあります。Facebookと同様に、ユーザーの友達がユーザーのフィードページ(表示ページ)にアクセスすると、ユーザーのステータスの更新についてコメントできるはずです。
ユーザーの友達のコメントを保存する際に問題が発生しました。私のコードは以下のとおりです。コメントコントローラーのCreateメソッドと関係があると思います。"@comment = @ statusupdate.comments.build(params [:comment]) 「」
どんなガイダンスでも大歓迎です!ありがとう!
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@statusupdates = @user.statusupdates.paginate(:page => params[:page], :per_page => 25)
@statusupdate = Statusupdate.new
@comment = Comment.new
end
end
show.html.erb
<% form_for @statusupdate do |f| %>
<%= f.error_messages %>
<div class="field">
<%= f.text_field :content %>
</div>
<% @statusupdates.each do |s| %>
<%= s.content %><br />
<% form_for @comment do |f| %>
<%= f.error_messages %>
<div class="field">
<%= f.text_field :comment %>
</div>
<div class="field">
<%= f.hidden_field :user_id, :value => current_user.id %>
</div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<br><br>
<% end %>
<% end %>
class CommentsController < ApplicationController
def create
@comment = @statusupdate.comments.build(params[:comment])
if @comment.save
flash[:success] = "Comment created!"
redirect_to root_path
else
@feed_items = []
render 'pages/home'
end
end
end