I have a model called notes. Here''s the definition in my schema.rb
create_table "notes", :force => true do |t|
t.column "sales_order_id", :integer
t.column "content", :text
t.column "timestamp", :datetime
t.column "user_id", :integer
end
The model class is as follows:
class Note < ActiveRecord::Base
belongs_to :sales_order
belongs_to :user
end
I''m trying to add a note by doing the following in the
sales_order_controller:
def add_note
da_note = Note.new
da_note.sales_order_id = params[:so_id]
da_note.content = params[:note_body]
da_note.user_id = cookies[:user_id]
da_note.timestamp = Time.now
if da_note.save!
flash[:notice] = ''Note added to Sales Order''
redirect_to :action => ''show'', :id =>
params[:so_id]
end
end
This works, but it adds the following text to the content field of every
note: "-- -". So if I type in ''test note'' and
submit, I get ''--- -
test note'' in the db. What am I doing wrong here?
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
are you calling debug() in your view anywhere? or to_yaml? On 4/17/07, Jason <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have a model called notes. Here''s the definition in my schema.rb > > create_table "notes", :force => true do |t| > t.column "sales_order_id", :integer > t.column "content", :text > t.column "timestamp", :datetime > t.column "user_id", :integer > end > > The model class is as follows: > > class Note < ActiveRecord::Base > belongs_to :sales_order > belongs_to :user > end > > I''m trying to add a note by doing the following in the > sales_order_controller: > > def add_note > da_note = Note.new > da_note.sales_order_id = params[:so_id] > da_note.content = params[:note_body] > da_note.user_id = cookies[:user_id] > da_note.timestamp = Time.now > > if da_note.save! > flash[:notice] = ''Note added to Sales Order'' > redirect_to :action => ''show'', :id => params[:so_id] > end > end > > This works, but it adds the following text to the content field of every > note: "-- -". So if I type in ''test note'' and submit, I get ''--- - > test note'' in the db. What am I doing wrong here? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> are you calling debug() in your view anywhere? or to_yaml?No, I tried that at first, but it didn''t help anything. I just now changed params[:note_body] to: params[:note_body].to_s and it worked! Why does it have to be changed to a string? Isn''t it already a string? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason wrote:> > params[:note_body].to_s and it worked! > > Why does it have to be changed to a string? Isn''t it already a string?Only you can tell us. Still a breakpoint in there and have a look at the params hash. Fred -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> Jason wrote: >> >> params[:note_body].to_s and it worked! >> >> Why does it have to be changed to a string? Isn''t it already a string? > > Only you can tell us. Still a breakpoint in there and have a look at the > params hash. > > FredI''m afraid you''ve gone over my head with that comment. What will the params hash tell me that I don''t already know? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you can just tail your development log and watch it as you post the data to the server. that should indicate where the problem is coming from. if you see -- - in your params hash (posted data) then the problem is in your view. if it''s not, then the problem is in your controller method On 4/17/07, Jason <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Frederick Cheung wrote: > > Jason wrote: > >> > >> params[:note_body].to_s and it worked! > >> > >> Why does it have to be changed to a string? Isn''t it already a string? > > > > Only you can tell us. Still a breakpoint in there and have a look at the > > params hash. > > > > Fred > > I''m afraid you''ve gone over my head with that comment. What will the > params hash tell me that I don''t already know? > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Unfortunately no. Unlike Smalltalk and many other languages, in Ruby Symbols are not strings. The value in params[:note_body] was apparently a symbol not a string. Michael On Apr 17, 7:12 am, Jason <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Chris Hall wrote: > > are you calling debug() in your view anywhere? or to_yaml? > > No, I tried that at first, but it didn''t help anything. > > I just now changed > > params[:note_body] > > to: > > params[:note_body].to_s and it worked! > > Why does it have to be changed to a string? Isn''t it already a string? > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> The value in params[:note_body] was apparently a symbol not a string.Ok, I guess it was a symbol, but I don''t have any idea how that happened. Oh well, it works now, at least. Thanks everybody! -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---