Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4- Associations -Tutorial Movielist
    primarykey
    data
    text
    <p>Hi I am trying to use Rails on Rest 2 - movielist tutorial with rails 4 and making adjustments as I go for new rails. I am stuck on associations of Movies Roles. I have added to Movie.rb </p> <pre><code>class Movie &lt; ActiveRecord::Base has_many :roles, :dependent =&gt; :destroy has_many :people, :through =&gt; :roles validates_presence_of :title def new_role=(values) values.each do |i, hash| unless hash[:name].blank? roles.create(:person_id =&gt; hash[:person_id], :name =&gt; hash[:name]) roles.save end end end def deleted_roles=(values) values.each do |role_id| roles.find(role_id).destroy end end end </code></pre> <p>and also to show _Form.html.rb that I render (excert below)</p> <pre><code> &lt;b&gt;Add New People&lt;/b&gt;&lt;br /&gt; &lt;% (1..3).each do |i| %&gt; &lt;%= select_tag 'movie_new_role_person_id', options_for_select(@people), { :name =&gt; "movie[new_role][#{i}][person_id]" } %&gt; &lt;%= text_field_tag 'movie_new_role_name', '', { :name =&gt; "movie[new_role][#{i}][name]" } %&gt;&lt;br /&gt; &lt;% end %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.submit "Update" %&gt; &lt;/p&gt; </code></pre> <p>It renders the list to choose from but when i submit - nothing is written to database table. If I manually enter data in database then it displays on movielist page ie: "Stephen Spielberg - Director" etc... Any help appreciated- Driving me nuts at this stage</p> <p>I thought it might be params driven restriction but I do not have a good example of associations style params filter</p> <p>Thanks</p> <p>Alan</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. 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