I''m having a problem passing along all parameters to post a comment: <%= form_tag :action => "comment", :id => @zwemmer, :created_on => Time.now, :created_by => "number1" %> <%= text_area "comment", "body" ,:size =>"25x10" %><br/> <%= submit_tag "Merk op!" %> </form> In the console i get: ←[4;36;1mComment Create (16.0ms)←[0m ←[0;1mINSERT INTO "comments" ("created_ on", "updated_at", "body", "zwemmer_id", "created_by", "created_at") VALUES(''201 1-04-07 18:06:56'', ''2011-04-07 18:06:56'', ''testcontent'', 124, NULL, ''2011-04-07 18:06:56'') So to created_by it''s passing NULL instead of "number1". How is this possible? -- Posted via http://www.ruby-forum.com/. -- 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.
On Thu, Apr 7, 2011 at 11:12 AM, Kelly Pfaff <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m having a problem passing along all parameters to post a comment: > > > <%= form_tag :action => "comment", :id => @zwemmer, :created_on => > Time.now, :created_by => "number1" %> > <%= text_area "comment", "body" ,:size =>"25x10" %><br/> > <%= submit_tag "Merk op!" %> > </form> > > In the console i get: > > ←[4;36;1mComment Create (16.0ms)←[0m ←[0;1mINSERT INTO "comments" > ("created_ > on", "updated_at", "body", "zwemmer_id", "created_by", "created_at") > VALUES(''201 > 1-04-07 18:06:56'', ''2011-04-07 18:06:56'', ''testcontent'', 124, NULL, > ''2011-04-07 > 18:06:56'') > > So to created_by it''s passing NULL instead of "number1". How is this > possible? > >Can you post your controller code that the form is submitting to? I''m curious to see how you are processing the values being sent over. B. -- 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.
In ZwemmersController: def comment Zwemmer.find(params[:id]).comments.create(params[:comment]) flash[:notice] = "Added new comment." redirect_to :action => "show", :id => params[:id] end -- Posted via http://www.ruby-forum.com/. -- 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 7 April 2011 17:12, Kelly Pfaff <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m having a problem passing along all parameters to post a comment: > > > <%= form_tag :action => "comment", :id => @zwemmer, :created_on => > Time.now, :created_by => "number1" %> > <%= text_area "comment", "body" ,:size =>"25x10" %><br/> > <%= submit_tag "Merk op!" %> > </form> > > In the console i get: > > ←[4;36;1mComment Create (16.0ms)←[0m ←[0;1mINSERT INTO "comments" > ("created_ > on", "updated_at", "body", "zwemmer_id", "created_by", "created_at") > VALUES(''201 > 1-04-07 18:06:56'', ''2011-04-07 18:06:56'', ''testcontent'', 124, NULL, > ''2011-04-07 > 18:06:56'') > > So to created_by it''s passing NULL instead of "number1". How is this > possible?If you look a little higher in your log, you''ll see the parameters that are getting passed in the POST request. Judging from your form, they''ll look something like this: :comment => {:body => "testcontent"}, :created_by => ''number1 The problem is that you probably want the :created_by key to be inside the :comment hash, not as a separate parameter. Otherwise, you''ll have to manually set the ''created_by'' attribute in your controller code, e.g.: @comment = Zwemmer.find(params[:id]).comments.build(params[:comment]) @comment.created_by = params[:created_by] @comment.save To avoid this, you want to make that ''created_by'' parameter part of the ''comment'' hash. One way to do this would be to pass it as a hidden field inside the form, rather than trying to add it to the form''s action URL: <%= hidden_field :comment, :created_by, ''number1'' %> so that your parameters would look like this: :comment => {:body => ''testcontent'', :created_by => ''number1''} and your controller code could be simply: Zwemmer.find(params[:id]).comments.create(params[:comment]) Chris -- 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.
Thanks for the fast reply, i added your code: <%= form_tag :action => "comment", :id => @zwemmer, :created_on => Time.now %> <%= hidden_field :comment, :created_by, ''number1'' %> <%= text_area "comment", "body" ,:size =>"25x10" %><br/> <%= submit_tag "Merk op!" %> </form> Now i am getting a TypeError ''can''t convert Symbol into String'' from that new line though. -- Posted via http://www.ruby-forum.com/. -- 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 8 April 2011 11:26, Kelly Pfaff <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks for the fast reply, i added your code: > > <%= form_tag :action => "comment", :id => @zwemmer, :created_on => > Time.now %> > <%= hidden_field :comment, :created_by, ''number1'' %> > <%= text_area "comment", "body" ,:size =>"25x10" %><br/> > <%= submit_tag "Merk op!" %> > </form> > > Now i am getting a TypeError ''can''t convert Symbol into String'' from > that new line though.Sorry, I always forget which bits of Rails take symbols versus strings. Try changing the parameters to hidden_field from symbols: :comment, :created_by to strings: ''comment'', ''created_by'' i.e. the same way you have it for your call to text_area on the next line. Chris -- 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.
No prob i found it via google, should be through :value: <%= hidden_field :comment, :created_by, :value => "number1" %> Everything working now, thanks much for the help! -- Posted via http://www.ruby-forum.com/. -- 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.