Note that there are some explanatory texts on larger screens.

plurals
  1. POHMBTM Checkboxes within Has_many relationship
    text
    copied!<p>I have one to many relationship between 'events' and 'tasks' and within show.html.erb I have render the following view:</p> <pre><code>&lt;%= form_for([@event, @event.tasks.build]) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :"Task name" %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;div class='cbx'&gt; &lt;%= f.label :'Assign To' %&gt;&lt;br /&gt; &lt;% for account in Account.find(:all) %&gt; &lt;%= check_box_tag "task[account_id][]", account.id %&gt; &lt;%= account.username %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>and when i actually process selection on the form it gives me the 1 in account_id, i have no idea why is this so</p> <p>Looking at the development log, found the following:</p> <pre><code> Started POST "/events/2/tasks" for 127.0.0.1 at Thu Jun 30 13:25:59 +1000 2011 Processing by TasksController#create as HTML Parameters: {"commit"=&gt;"Create Task", "event_id"=&gt;"2","authenticity_token"=&gt;"oSxcZZ/NCH+OyP+UoRSMvmHCP1daPbmJBeJM6tLxhyA=", "utf8"=&gt;"✓", "task"=&gt;{"name"=&gt;"t", "account_id"=&gt;["6"]}} Event Load (0.2ms) SELECT "events".* FROM "events" WHERE "events"."id" = 2 LIMIT 1 AREL (0.4ms) INSERT INTO "tasks" ("created_at", "user_id", "event_id", "updated_at", "name", "account_id") VALUES ('2011-06-30 03:25:59.327287', NULL, 2, '2011-06-30 03:25:59.327287', 't', 1) </code></pre> <p>Do you have any idea why is this so? why it puts 6 in account_id but doesn't update the database?</p> <p>And if you have any other comments please feel free to comment, I'm beginner so I really wish to learn a lot.</p> <p>Thank you in advance</p>
 

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