Forum: Ruby on Rails text_field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Junichi G. (Guest)
on 2006-05-02 21:06
Hi, All.

Is it possible to use the text_field with an instance variable.

Controller:
def hoge
  @value = 'result'
end

View:
<%= text_field 'value' %>

It don't work.
Please help.
Junichi G. (Guest)
on 2006-05-03 10:33
<%= text_field 'value', 'to_s' %>
Is it strange?
Any idea?
Philip R. (Guest)
on 2006-05-03 21:01
(Received via mailing list)
Junichi Goza wrote:
> Is it possible to use the text_field with an instance variable.
>
> Controller:
> def hoge
>   @value = 'result'
> end
>
> View:
> <%= text_field 'value' %>

You can't use text_field as that only works with objects. There is a
text_field_tag helper method that should do the job though:

<%= text_field_tag 'value', @value %>

--
Philip R.
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
This topic is locked and can not be replied to.