undefined method `build_

def create
@school = current_user.build_school(school_params)

causes the above error my models are users has_one profile, profile has_many schools, profile belongs_to user, school belongs_to profile

What makes you think that current_user.build_school is valid code?

Colin

Why not kindly pointing out the error and offer a suggestion to assist the OP instead?

Yes. I'm top posting.

Why not kindly pointing out the error and offer a suggestion to assist the OP instead?

Because one learns more by working out the error for oneself. If the
OP goes and looks at the documentation that he thought said that he
should be able to do this then he will see the error. If he cannot
work it out then I assume he will ask again.

Yes. I'm top posting.

Should I just point out the way to fix that or should I point you to
documentation that will help you to fix it for yourself?

Colin

No, you've mentioned top posting and your dislike of it countless times. :hot_pepper:

Sorry Colin I fell asleep Here’s how I worked it out
<%= form_for(@school) do |school_form| %>
<% school_form.fields_for :profiles do |f| %>

what should the create action be

@school = current_user.create_school(school_params)

If a user has many schools you would want

has_one :profile, dependent: :destroy
has_many :schools, through: :profile, dependent: :destroy

@school = current_user.create_school(school_params)

undefined method `create_school’ for #User:0xb4c85050

that’s a reference to the new action, i’m asking about the create action where create_association is used, not build_association

@school = current_user.create_school(school_params)

undefined method `create_school’ for #User:0xb4e407a0


i see, but that results in Mysql2::Error: Duplicate entry ‘0’ for key ‘PRIMARY’: INSERT INTO schools VALUES ()