家主クラス、コメント クラスがあり、家主には多くのコメントがあります (1:N)
フォームを送信するたびに (フォームは @landlord で、フォームにネストされたコメントが含まれています)、コメント データベースに 3 つの挿入を作成しています。この問題の原因を特定するのに苦労しています。私が欲しいのは、家主が作成され、保存されると、コメントが家主に関連付けられ、データベースに保存されることです。
私はcomments#createが呼び出されていないことを確信しています。
私はレールに不慣れで、助けに感謝しています。ありがとうございました。
landlords_controller
def new
@landlord = Landlord.new
@landlord.comments.build
end
def create
@landlord = Landlord.create(params[:landlord])
if @landlord.save
flash[:success] = "Thank you for submitting a Landlord"
redirect_to landlords_path
else
end
end
コメント_コントローラー
def create
@comment = landlord.comments.build(params[:comment])
if @comment.save
@comment.setIP request.remote_ip
else
end
end