Help! Can anyone see why my code isn''t inserting the course_id parameter into my table? <p> <%= f.label :course_id %><br /> <t1> <% for course in current_user.courses.find(:all, :order => ''order_taught'') %> <%= check_box_tag ''assessment[course_id][]'', course.id %> <%=h course.name %> <% end %> </p> Below, you can see the Development Log. It shows that the parameter for "course_id"=>["2"]. But as you can see, the INSERT INTO is inserting a value of 1 for course_id: Processing AssessmentsController#create (for 127.0.0.1 at 2010-01-16 16:27:24) [POST] Parameters: {"commit"=>"Create", "authenticity_token"=>"Z8yZOo9q2tz6IC1jmV33qvMO7ULRzcJ8e7q6B0xHP9Y=", "assessment"=>{"name"=>"", "date(1i)"=>"2010", "date(2i)"=>"1", "date (3i)"=>"16", "standard_id"=>"9", "course_id"=>["2"], "strand_id"=>"2"}} [4;36;1mUser Load (0.0ms) [0;1mSELECT * FROM "users" WHERE ("users"."id" = 12) LIMIT 1 [4;35;1mAssessment Create (0.0ms) INSERT INTO "assessments" ("name", "created_at", "updated_at", "date", "user_id", "standard_id", "strand_id", "course_id") VALUES('''', ''2010-01-17 00:27:24'', ''2010-01-17 00:27:24'', ''2010-01-16'', 12, 9, 2, 1) Any help would be greatly appreciated! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 16, 7:37 pm, Demetrius <demetri...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Help! Can anyone see why my code isn''t inserting the course_id > parameter into my table? > > <p> > <%= f.label :course_id %><br /> > <t1> > <% for course in current_user.courses.find(:all, :order => > ''order_taught'') %> > > <%= check_box_tag ''assessment[course_id][]'', course.id %> > <%=h course.name %> > > <% end %> > </p> > > Below, you can see the Development Log. It shows that the parameter > for "course_id"=>["2"]. But as you can see, the INSERT INTO is > inserting a value of 1 for course_id: >Not sure where the 1 is coming from, but what you''re doing still doesn''t make sense. What is the expected behavior if the user checks two boxes, passing :course_id => ["2", "5"] in? You may have a belongs_to/has_many reversed here... --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2010/1/17 Demetrius <demetriuso-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>:> Help! Can anyone see why my code isn''t inserting the course_id > parameter into my table? > > <p> > <%= f.label :course_id %><br /> > <t1> > <% for course in current_user.courses.find(:all, :order => > ''order_taught'') %> > > <%= check_box_tag ''assessment[course_id][]'', course.id %> > <%=h course.name %> > > <% end %> > </p> > > > Below, you can see the Development Log. It shows that the parameter > for "course_id"=>["2"]. But as you can see, the INSERT INTO is > inserting a value of 1 for course_id:I guess the problem is that course_id is being passed as an array due to the [] in the check_box_tag call. Would a radio set be more appropriate so only one can be selected? Colin> > Processing AssessmentsController#create (for 127.0.0.1 at 2010-01-16 > 16:27:24) [POST] > Parameters: {"commit"=>"Create", > "authenticity_token"=>"Z8yZOo9q2tz6IC1jmV33qvMO7ULRzcJ8e7q6B0xHP9Y=", > "assessment"=>{"name"=>"", "date(1i)"=>"2010", "date(2i)"=>"1", "date > (3i)"=>"16", "standard_id"=>"9", "course_id"=>["2"], > "strand_id"=>"2"}} > [4;36;1mUser Load (0.0ms) [0m [0;1mSELECT * FROM "users" WHERE > ("users"."id" = 12) LIMIT 1 [0m > [4;35;1mAssessment Create (0.0ms) [0m [0mINSERT INTO > "assessments" ("name", "created_at", "updated_at", "date", "user_id", > "standard_id", "strand_id", "course_id") VALUES('''', ''2010-01-17 > 00:27:24'', ''2010-01-17 00:27:24'', ''2010-01-16'', 12, 9, 2, 1) > > Any help would be greatly appreciated! > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Demetrius, could you show us the controller code which handles that form? On 17 ene, 17:47, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2010/1/17 Demetrius <demetri...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>: > > > > > > > Help! Can anyone see why my code isn''t inserting the course_id > > parameter into my table? > > > <p> > > <%= f.label :course_id %><br /> > > <t1> > > <% for course in current_user.courses.find(:all, :order => > > ''order_taught'') %> > > > <%= check_box_tag ''assessment[course_id][]'', course.id %> > > <%=h course.name %> > > > <% end %> > > </p> > > > Below, you can see the Development Log. It shows that the parameter > > for "course_id"=>["2"]. But as you can see, the INSERT INTO is > > inserting a value of 1 for course_id: > > I guess the problem is that course_id is being passed as an array due > to the [] in the check_box_tag call. Would a radio set be more > appropriate so only one can be selected? > > Colin > > > > > > > Processing AssessmentsController#create (for 127.0.0.1 at 2010-01-16 > > 16:27:24) [POST] > > Parameters: {"commit"=>"Create", > > "authenticity_token"=>"Z8yZOo9q2tz6IC1jmV33qvMO7ULRzcJ8e7q6B0xHP9Y=", > > "assessment"=>{"name"=>"", "date(1i)"=>"2010", "date(2i)"=>"1", "date > > (3i)"=>"16", "standard_id"=>"9", "course_id"=>["2"], > > "strand_id"=>"2"}} > > [4;36;1mUser Load (0.0ms) [0m [0;1mSELECT * FROM "users" WHERE > > ("users"."id" = 12) LIMIT 1 [0m > > [4;35;1mAssessment Create (0.0ms) [0m [0mINSERT INTO > > "assessments" ("name", "created_at", "updated_at", "date", "user_id", > > "standard_id", "strand_id", "course_id") VALUES('''', ''2010-01-17 > > 00:27:24'', ''2010-01-17 00:27:24'', ''2010-01-16'', 12, 9, 2, 1) > > > Any help would be greatly appreciated! > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.