How to create an association between two rails models

后端 未结 5 1133
南笙
南笙 2021-01-16 12:07

This is a newbie question, but I\'m still learning how to create an association between two models in rails. I have a user model and a journal_entry model. The journal entri

5条回答
  •  一向
    一向 (楼主)
    2021-01-16 12:47

    i bet, that u forget something like

    def create
        @journal_entry = @user.journal_entries.build(params[:journal_entry])
        # @journal_entry = current_user.journal_entries.build(params[:journal_entry])
        if @journal_entry.save
        ..
    

提交回复
热议问题