<p> <label for="person_languages">Languages</label> <%= text_field ''person'', ''languages'', {:value => "English" } %> </p> I only want to send the value of "English" if @person.languages.empty? Rails doesn''t like my attempts so far. Has anyone been able to do this? -- 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 -~----------~----~----~----~------~----~------~--~---
Have you tried this? <p> <label for="person_languages">Languages</label> <%= if @person.languages.empty? text_field ''person'', ''languages'', {:value => "English" } else text_field ''person'', ''languages'' end %> </p> Hope that helps, Matt Buck --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Or, [and I think I remember this working for me] <p> <label for="person_languages">Languages</label> <% val = @person.languages.empty? ? nil : "English" -%> <%= text_field "person", "languages", {:value => val} %> </p> I''m pretty sure the nil value doesn''t get added to the options for the text_field. It doesn''t [if I recall correctly] on a link_to. And it''s a lot more DRY. RSL On 12/20/06, Matt Buck <techpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Have you tried this? > > <p> > <label for="person_languages">Languages</label> > <%= if @person.languages.empty? > text_field ''person'', ''languages'', {:value => "English" } > else > text_field ''person'', ''languages'' > end %> > </p> > > Hope that helps, > Matt Buck > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Matt. I ended up using this to deal with absent variables in new users while preserving user attributes in edits: <p> <label for="person_languages">Languages</label> <%= if @person.languages && !@person.languages.empty? text_field ''person'', ''languages'' else text_field ''person'', ''languages'', {:value => "English" } end %> </p> -- 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 -~----------~----~----~----~------~----~------~--~---