Value for text_field_tag?

Hi!

I have this in my controller:
@text = params[:data][:text]

In the view, I have this code:
<%= label_tag(‘data[text]’, "Word/phrase: ") %>

<%= text_field_tag( ‘data[text]’, @text, :size => 40, :maxlength =>
254 ) %>

What I would like to have is to get a default value for the form
field (some text that the user previously entered). I cannot figure
out why @text controller instance variable doesn’t work. It’s a non-
empty string, but the corresponding form
field is always blank. :frowning:

However, this piece of code always works,
<%= text_field_tag( ‘data[text]’, ‘STATIC STRING’, :size =>
40, :maxlength => 254 ) %>

What am I missing here? :-/

Tuo

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

2009/12/21 T_P [email protected]:

What I would like to have is to get a default value for the form
field (some text that the user previously entered). I cannot figure
out why @text controller instance variable doesn’t work. It’s a non-
empty string, but the corresponding form
field is always blank. :frowning:

Are you sure @text contains something? What do you see if you include
something like

<%= @text %>

before the text_field_tag.

Also have a look at the html of the page (View, Page Source or similar
in browser) and see what the field html looks like. If the value is
there in the html but does not appear on screen, copy all the page
html source and enter it into the w3c html validator at
The W3C Markup Validation Service and see if there are html
errors which could be confusing the browser.

Colin

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Hi, Colin. Thanks for replying.

Are you sure @text contains something? What do you see if you include
something like

<%= @text %>

before the text_field_tag.

I see an empty paragraph. :frowning:

Also have a look at the html of the page (View, Page Source or similar
in browser) and see what the field html looks like. If the value is
there in the html but does not appear on screen, copy all the page
html source and enter it into the w3c html validator athttp://validator.w3.org/#validate_by_inputand see if there are html
errors which could be confusing the browser.

It did NOT validate. This is one of the errors,

Line 59, Column 31: character “[” is not allowed in the value of
attribute “id”

2009/12/21 T_P [email protected]:

Hi, Colin. Thanks for replying.

Are you sure @text contains something? What do you see if you include
something like

<%= @text %>

before the text_field_tag.

I see an empty paragraph. :frowning:

In that case @text is empty, so that is the problem to be fixed.
Unless the error below is causing it to show empty which does not seem
likely.

If you have trouble working out why @text is empty it may be worth
while having a look at the RoR guide on Debugging at
http://guides.rubyonrails.org. I find ruby-debug very useful when
code inspection does not reveal the problem.

attribute “id”

</textar It is possible that you violated the naming convention for this attribute. For example, id and name attributes must begin with a letter, not a digit.

You will have to not include [ ] in your name string.

Colin

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.