Newbie: Proper way to set default text_field form value?

I’m using the _form.rhtml partial for both the new.rhtml and edit.rhtml
views like this:

<% if @product.cost %>
<%= text_field ‘product’, ‘cost’, :size => 5 %>
<% else %>
<%= text_field ‘product’, ‘cost’, :size => 5, :value => 0 %>
<% end %>

I couldn’t find a :defaultvalue or similar hash parameter and not sure
how I’d add an “if not nil” statement to the form helper.

If there’s proper way to do this I’d be interested to learn.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs