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.
C1283de982cc8ae7a62216e3172782fb?d=identicon&s=25 Junichi Goza (jgoza)
on 2006-05-02 19: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.
C1283de982cc8ae7a62216e3172782fb?d=identicon&s=25 Junichi Goza (jgoza)
on 2006-05-03 08:33
<%= text_field 'value', 'to_s' %>
Is it strange?
Any idea?
9ab183bb240ffd3a3966d5a615b4bdeb?d=identicon&s=25 Philip Ross (Guest)
on 2006-05-03 19: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 Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
This topic is locked and can not be replied to.