text_field
text_field(object_name, method, options = {})
public
Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). Additional options on the input tag can be passed as a hash with options.
Examples (call, result):
text_field("post", "title", "size" => 20) <input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />
Force initial value
If you want to force an initial value for your text_field which is normally based on your object attribute value, you can use :
text_field :ecard, :sender, :value => 'contact@host.com'
Alternative force initial value
@Bounga - Thanks for the suggestion. Didn’t know about that method. An alternative method I have used is just to assign the default value to the object in your controller. For example your “new” action might now look like:
def new @ecard = Ecard.new params[:ecard] @ecard.sender ||= 'contact@host.com' end
Re: Force initial value
An alternative to @eric_programmer’s would be to extract it entirely from the controller logic…
class Person def sender self[:sender] || 'contact@host.com' end end
There are a ton of ways to do it, but making this a business logic decision will let you get the same logic from any possible implementation angle. Scripts, web service, etc.


