Help us understand the problem. What is going on with this article?

has_manyなリレーションで外部キーを作り忘れるとNoMethodErrorが発生する

More than 5 years have passed since last update.
class Blog < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
end

で、

irb(main):001:0> Blog.find(1).posts.build
NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x0000080fdff388>

となる。

Postのほうにblog_idを作り忘れているとこうなる。

親切なエラーメッセージが出るような変更がcommitされてるようなのでそのうち治るでしょう。

suzukis
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away