Problem
You would like to use the build method for creating an association (details) that belongs to another assocation (user).
When the user has many details then you would have something like the following:
1 2 3 |
class User < ActiveRecord::Base has_many :details end |
then you could do:
1 |
User.details.build |
but when you have:
1 2 3 |
class User < ActiveRecord::Base has_one :detail end |
would throw an error:
1 |
NoMethodError: undefined method `build' ... |
Solution
In order to be able to use the build in a has_one relation you would need to use like:
1 |
User.build_detail |