Rails has_one:through - undefined方法create_

时间:2017-12-19 18:22:17

标签: ruby-on-rails activerecord

我收到了这个错误:

undefined method `create_postconversation' for #<Post...>

......源于这一行:

posts_controller.rb

@postconversation = @post.create_postconversation

我做错了什么?

post.rb

has_one :postconvo, foreign_key: "post_id", dependent: :destroy
has_one :postconversation,  through: :postconvo,
                            class_name: "Conversation",
                            source: :conversation

postconvo.rb

belongs_to :post
belongs_to :conversation

validates :post_id, presence: true
validates :conversation_id, presence: true

conversation.rb

has_one :postconvo, foreign_key: "conversation_id", dependent: :destroy
has_one :post, through: :postconvo, source: :post

0 个答案:

没有答案