Hi All, I am fairly new to rails. I am trying to cycle through an array of activerecord objects and the view signals an error when I try to display fields that are not specified. I had expected the unspecified fields to return empty strings. What''s the rationale in returning nil? What''s the best way to deal with this? Currently I am calling the to_s method for each field, but this doesn''t seem very elegant. Thanks! Will -- 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 -~----------~----~----~----~------~----~------~--~---
If the fields are not defined in your database table, then rails cannot create attributes for them in the ActiveRecord object. -- 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 -~----------~----~----~----~------~----~------~--~---
Mick Sharpe wrote:> If the fields are not defined in your database table, then rails cannot > create attributes for them in the ActiveRecord object.They are defined. The schema is generated in migration for mysql5. It''s just that when the field is empty it returns nil instead of an empty string. When there are values in the field it works fine, but when it returns nil it generates an error. -- 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-19 06:49 UTC
Re: Nil Instead of Empty String
Can you pastie - http://pastie.caboo.se - us some code? On Jan 19, 5:52 am, Willis 3000 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Mick Sharpe wrote: > > If the fields are not defined in your database table, then rails cannot > > create attributes for them in the ActiveRecord object.They are defined. The schema is generated in migration for mysql5. > It''s just that when the field is empty it returns nil instead of an > empty string. When there are values in the field it works fine, but > when it returns nil it generates an error. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
> They are defined. The schema is generated in migration for mysql5. > It''s just that when the field is empty it returns nil instead of an > empty string. When there are values in the field it works fine, but > when it returns nil it generates an error.Let''s make it clear: is the field NULL in database, or is it indeed empty? These are not the same. Regards, Rimantas -- http://rimantas.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 -~----------~----~----~----~------~----~------~--~---