多くのリソースを調べましたが、これを理解できないようです。
BinaryMuse によるこのコードに基づくメッセージング システムに取り組んでいます。
https://github.com/BinaryMuse/so_association_expirement/compare/53f2263...マスター
応答機能がないので、構築しようとしています。
UserConversations コントローラーに次のコードを追加しました。
def update
@user = User.find params[:user_id]
@conversation = UserConversation.find params[:id]
@conversation.user = current_user
@message = @conversation.messages.build
@message.conversation_id = @conversation
@message.save
redirect_to user_conversation_path(current_user, @conversation)
end
そして、UserConversations#show ビューに以下を追加します。
<%= form_for(@conversation) do |f| %>
<%= f.fields_for :messages do |m| %>
<div>
<%= m.label :body %><br />
<%= m.text_area :body %>
</div>
<% end %>
<%= f.submit %>
私が持っているもので、正しい conversation_id を持つ新しいメッセージが作成されます。ただし、body または user_id は関連付けられていません。
私が間違っていることはありますか?
よろしくお願いします。