Languages <%= text_field 'person', 'languages', {:value => "English" } %>
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?
Languages <%= text_field 'person', 'languages', {:value => "English" } %>
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?
Have you tried this?
Languages <%= if @person.languages.empty? text_field 'person', 'languages', {:value => "English" } else text_field 'person', 'languages' end %>
Hope that helps,
Matt Buck
Thanks, Matt. I ended up using this to deal with absent variables in
new users while preserving user attributes in edits:
Languages <%= if @person.languages && [email protected]? text_field 'person', 'languages' else text_field 'person', 'languages', {:value => "English" } end %>
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs