Hi! I have this in my controller: @text = params[:data][:text] In the view, I have this code: <%= label_tag(''data[text]'', "Word/phrase: ") %> <br /> <%= 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. :-( 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/21 T_P <tuo_pe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>:> Hi! > > I have this in my controller: > @text = params[:data][:text] > > In the view, I have this code: > <%= label_tag(''data[text]'', "Word/phrase: ") %> <br /> > <%= 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. :-(Are you sure @text contains something? What do you see if you include something like <p><%= @text %></p> 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 http://validator.w3.org/#validate_by_input 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. 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 > <p><%= @text %></p> > before the text_field_tag.I see an empty paragraph. :-(> 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" <textarea cols="40" id="data[comment]" name="data[comment]" rows="10"></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. I will dwell on this issue later. Right not I have to catch the bus. ;-) I will one modification to the code and see what''s gonna happen. T -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/21 T_P <tuo_pe-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>:> Hi, Colin. Thanks for replying. > >> Are you sure @text contains something? What do you see if you include >> something like >> <p><%= @text %></p> >> before the text_field_tag. > > I see an empty paragraph. :-(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.> >> 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" > <textarea cols="40" id="data[comment]" name="data[comment]" > rows="10"></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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.