The value in text_field helper

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,


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 D. for Rails if you haven’t
done so already… This type of stuff is outlined in the book.


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


simply don’t use a redirect, but

render :action => :traveler_form

On 21 Jul., 00:13, Shandy N. [email protected]

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


  1. 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.