undefined method `build_

48 views
Skip to first unread message

fugee ohu

unread,
Jan 2, 2016, 3:51:12 PM1/2/16
to Ruby on Rails: Talk
  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

Colin Law

unread,
Jan 2, 2016, 4:45:20 PM1/2/16
to Ruby on Rails: Talk
What makes you think that current_user.build_school is valid code?

Colin

jel...@gmail.com

unread,
Jan 2, 2016, 5:22:06 PM1/2/16
to rubyonra...@googlegroups.com
Why not kindly pointing out the error and offer a suggestion to assist the OP instead?

Yes. I'm top posting.
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuZmYtmNi_9jWESuqO5ru_sp78uY7FwAtVo-VAg0BbaNg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Colin Law

unread,
Jan 2, 2016, 5:39:24 PM1/2/16
to Ruby on Rails: Talk
On 2 January 2016 at 22:21, <jel...@gmail.com> wrote:
> 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
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1B5726EC-44E1-4E59-88D2-4536B5BD68BC%40gmail.com.

jel...@gmail.com

unread,
Jan 2, 2016, 6:20:57 PM1/2/16
to rubyonra...@googlegroups.com
No, you've mentioned top posting and your dislike of it countless times. 🌶
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvpK_bAGGNnxqW2Mb4E2g56hVfHGaoRVWiwLD8d8Vitiw%40mail.gmail.com.

fugee ohu

unread,
Jan 2, 2016, 7:17:18 PM1/2/16
to Ruby on Rails: Talk
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| %>
Message has been deleted

fugee ohu

unread,
Jan 2, 2016, 7:32:36 PM1/2/16
to Ruby on Rails: Talk
what should the create action be
    @school = current_user.create_school(school_params)

On Saturday, January 2, 2016 at 4:45:20 PM UTC-5, Colin Law wrote:

jel...@gmail.com

unread,
Jan 2, 2016, 7:38:13 PM1/2/16
to rubyonra...@googlegroups.com
If a user has many schools you would want

current_user.schools.new(school_params)

Unfortunately I don't know how your associations are setup so I'm taking a guess at this. 👍🏻
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

fugee ohu

unread,
Jan 2, 2016, 7:45:06 PM1/2/16
to Ruby on Rails: Talk

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

fugee ohu

unread,
Jan 2, 2016, 8:07:33 PM1/2/16
to Ruby on Rails: Talk

On Saturday, January 2, 2016 at 7:38:13 PM UTC-5, James Jelinek wrote:

    @school = current_user.create_school(school_params)

undefined method `create_school' for #<User:0xb4c85050>

fugee ohu

unread,
Jan 2, 2016, 8:17:59 PM1/2/16
to Ruby on Rails: Talk
that's a reference to the new action, i'm asking about the create action where create_association is used, not build_association


On Saturday, January 2, 2016 at 7:38:13 PM UTC-5, James Jelinek wrote:

fugee ohu

unread,
Jan 2, 2016, 8:20:20 PM1/2/16
to Ruby on Rails: Talk

   @school = current_user.create_school(school_params)

undefined method `create_school' for #<User:0xb4e407a0>

fugee ohu

unread,
Jan 2, 2016, 8:40:40 PM1/2/16
to Ruby on Rails: Talk

On Saturday, January 2, 2016 at 7:38:13 PM UTC-5, James Jelinek wrote:

i see, but that results in Mysql2::Error: Duplicate entry '0' for key 'PRIMARY': INSERT INTO `schools` VALUES ()
Reply all
Reply to author
Forward
0 new messages