Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out. It turns out a few things were wrong and needed to be changed in addition to the two suggestions @Delba made.</p> <p><strong>The Form:</strong></p> <p>I took a look at <a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow noreferrer">RailsCasts #196</a> again and noticed that my form looked different than the one used there, so I tried to match it up: </p> <pre><code> &lt;%= form_for @service_offering do |f|%&gt; &lt;p&gt; &lt;%= f.label :name%&gt; &lt;%= f.text_field :name %&gt; &lt;%= f.label :description %&gt; &lt;%= f.text_field :description %&gt; &lt;/p&gt; &lt;%= f.fields_for :business_developers do |builder| %&gt; &lt;p&gt; &lt;%= builder.label :first_name %&gt; &lt;%= builder.text_field :first_name %&gt; &lt;%= builder.label :last_name %&gt; &lt;%= builder.text_field :last_name %&gt; &lt;/p&gt; &lt;%end%&gt; &lt;%= f.submit "Submit" %&gt; &lt;%end%&gt; </code></pre> <p>Initially, this presented an error: </p> <pre><code>undefined method `service_offerings_path' </code></pre> <p><strong>Routes:</strong></p> <p>This lead me to learn about <a href="http://guides.rubyonrails.org/routing.html" rel="nofollow noreferrer">RESTful Routes</a> because I was using the old routing style:</p> <pre><code>match ':controller(/:action(/:id(.:format)))' </code></pre> <p>So I updated my routes to the new RESTful Routes style:</p> <pre><code> get "service_offerings/list" resource :service_offerings resource :business_developers </code></pre> <p><strong>attr_accessible</strong>:</p> <p>That got the form visible but it was still not working. So I did some searching around on this site and found <a href="https://stackoverflow.com/questions/6714286/nested-attributes-are-not-updating-in-rails">this post</a> that talked about adding "something_attributes" to your parent objects model under attr_accessible. So I did:</p> <pre><code>class ServiceOffering &lt; ActiveRecord::Base has_many :business_developer_service_offerings has_many :business_developers, :through =&gt; :business_developer_service_offerings accepts_nested_attributes_for :business_developers attr_accessible :name, :description, :business_developers_attributes end </code></pre> <p>That change along with @Delba's suggestion shown in the above model and controller listed below solved it.</p> <pre><code>def new @service_offering = ServiceOffering.new @business_developer = @service_offering.business_developers.build end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload