Forum: Ruby on Rails the value in text_field helper

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-07-20 21:39
I have been working on this small, minute, part on my project and it all
hinges on setting the value in a text_field helper. Saying:

<%= text_field  'user', 'company', :value => @login  %>

does not do it. When I go and look at the raw html, there is no value
there and "value" is an attribute of the input tag, im pretty sure. I
really like RoR and how things work, but they fail miserably when it
comes to documentation. Anybody know of any good reference sites besides Thanks,

581905e940c1e30190108a0c5c0b915b?d=identicon&s=25 Adam Cohen (Guest)
on 2007-07-20 22:08
(Received via mailing list)
the text_field helper expects the first parameter to be an instance
variable.  The second parameter is the method that will be called on
the instance variable to populate the value of the text field.  So if
you have the following:


def new
@user =[:user])


<%= text_field :user, :first_name %>

the field will contain the value of the user's first name (providing
that you have a "first_name" attribute in your users table in your
database).  If the user doesn't have a first name (ie the record is
new), then the value will be blank.

If you want more control about how the text field's value is
populated, you can use the following:

text_field_tag 'name of text field', @value

you should read through Agile Web Development for Rails if you haven't
done so already.. This type of stuff is outlined in the book.

C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-07-21 00:13
Yeah, it works, to a point. My issue is that you start out at a
"traveler_form.rhtml." On submit, the :action 'create_user' is performed
and when the log-in fails a redirect_to reloads the traveler_form. But
before that, the controller for the traveler_form, the 'traveler_form'
method gets called, correct? At least this is the way that I understand
the flow of data in the program. The information basically is getting
lost in this loop. I'm just trying to figure out what I'm missing or not
understanding? Thanks

D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-07-21 13:39
(Received via mailing list)
simply don't use a redirect, but

render :action => :traveler_form

On 21 Jul., 00:13, Shandy Nantz <>
F7868264da954faaa158256820e7fa74?d=identicon&s=25 Niaz Arifin (arif)
on 2007-07-23 21:42
(Received via mailing list)
I have a similar problem:
I need to:

1. put a 'reset' button so that I can clear (set to blank) the
text_field when the user clicks on the button


2. retain value in text_field: I have a 'search' button that performs
search (not Ajax livesearch... it's a simple search and I wrote the
code in my controller). Now, when the user puts some text (query) in
the text_field and clicks on 'search', the results are shown ok, but I
need to retain the text in the text-field that the user put in. Also I
need to set the focus to this text_field after the results are shown.

The relevant code in the view is:
  <%= start_form_tag :action => 'search'%>
    <%= text_field :server, :server_name, :size => 15  %>
    <%= submit_tag 'Search' %>
  <%= end_form_tag %>
  <%= set_focus_to_id 'server_server_name' %>

The controller code for 'search' is:
def search
  condition = ""
  var = ""
  if !params[:server][:server_name].blank?
    column_query = params[:server][:server_name]
    var = params[:server][:server_name]
    condition_part = "lower(s.server_name) like \'%" +
column_query.downcase + "%\'"
    condition = condition + condition_part
    and_flag = 1
  if !condition.blank?
    sql = "
      select s.server_name, s.server_type_code from server s
      where " +
  @server_pages, @servers = paginate_by_sql Server, sql, 30
   render :partial => "search", :layout => "application"

Your help would be greatly appreciated. Thanks.
This topic is locked and can not be replied to.