Hi I''d like to know how to add default text text area using the function text_area. I ''ve tried using value = "....." to do this but with no luck. Could some one please answer my simple question? Thanks. Dan. -- Posted via http://www.ruby-forum.com/.
Hi Daniel, On 21.12.2005, at 11.29, Daniel Perrett wrote:> Hi I''d like to know how to add default text text area using the > function > text_area. I ''ve tried using value = "....." to do this but with no > luck.If you look at the api docs for text_area [1], you can see that the function (like most Rails view helpers) has an optional parameter called "options". Options is a hash that can contain values passed to the resulting html tag as attributes. Since it''s a hash, you need to specify the options like "value" => "....". So the whole function call would look something like <%= text_area("post", "body", "value" => "....") %> //jarkko [1] http://api.rubyonrails.com/classes/ActionView/Helpers/ FormHelper.html#M000345> Could some one please answer my simple question? > > Thanks. > Dan. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine wrote: I''ve just tried this, and I''m sure I have done before using this piece of code. <%= text_area( "user", "tasks", "value" => "This is a test", :cols=>30, :rows=>10) %> It does not display "This is a test" in the text area!?! The text area just comes up blank as before. am I doing something wrong? Cheers. Dan. -- Posted via http://www.ruby-forum.com/.
Daniel Perrett wrote:> Hi I''d like to know how to add default text text area using the function > text_area. I ''ve tried using value = "....." to do this but with no > luck.The text area is populated with the value of the associated variable attribute. For a page containing a new and empty form, you create (and pass to the view) an empty object (see the "new" action generated by scaffolding). If this object already contains the default value, the text area will contain it too. -- Posted via http://www.ruby-forum.com/.
On 21.12.2005, at 12.09, Daniel Perrett wrote:> Jarkko Laine wrote: > I''ve just tried this, and I''m sure I have done before using this piece > of code. > <%= text_area( "user", "tasks", "value" => "This is a > test", :cols=>30, > :rows=>10) %> > > It does not display "This is a test" in the text area!?! > The text area just comes up blank as before. > am I doing something wrong?Oops, sorry. There is no attribute called value for the textarea html element [1]. The actual value of the element is put between the tags. However, you can prepopulate it by setting the @user.tasks to be the default text in case of a new entry. The current value will be automatically used as the default text by text_area. //jarkko [1] http://www.w3schools.com/tags/tag_textarea.asp> > Cheers. > Dan. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine wrote:> Oops, sorry. There is no attribute called value for the textarea html > element [1]. The actual value of the element is put between the tags. > However, you can prepopulate it by setting the @user.tasks to be the > default text in case of a new entry. The current value will be > automatically used as the default text by text_area. > > //jarkko > > [1] http://www.w3schools.com/tags/tag_textarea.aspCould you clarify how to do this with a example please? -- Posted via http://www.ruby-forum.com/.
On 21.12.2005, at 12.48, Daniel Perrett wrote:> Jarkko Laine wrote: >> Oops, sorry. There is no attribute called value for the textarea html >> element [1]. The actual value of the element is put between the tags. >> However, you can prepopulate it by setting the @user.tasks to be the >> default text in case of a new entry. The current value will be >> automatically used as the default text by text_area. >> >> //jarkko >> >> [1] http://www.w3schools.com/tags/tag_textarea.asp > > Could you clarify how to do this with a example please?In the controller you have something like @user = User.new After that, put this: @user.tasks = "...." Then the text_area helper will automatically put the dots as the prepopulated value. Note that you shouldn''t be (and probably weren''t) doing this in an edit (as opposed to create) form where the very same form helper will populate the area with the real, existing value of the db field "tasks". //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko Laine wrote:> @user = User.new > > After that, put this: > @user.tasks = "...." > > Then the text_area helper will automatically put the dots as the > prepopulated value. Note that you shouldn''t be (and probably weren''t) > doing this in an edit (as opposed to create) form where the very same > form helper will populate the area with the real, existing value of > the db field "tasks". > > //jarkkoI don''t think this would work as I have no class called User! I''ve given up and gone back to the old tried and tested method <textarea .........>some text</textarea> it does the job. -- Posted via http://www.ruby-forum.com/.
On 21.12.2005, at 13.30, Daniel Perrett wrote:> I don''t think this would work as I have no class called User! > > I''ve given up and gone back to the old tried and tested method > <textarea .........>some text</textarea> it does the job.Ah, you got to have an object at hand to use text_area, text_field etc. helpers. It doesn''t matter what class it is, as long as it responds to the method you specify in the second parameter. Take a look at text_area_tag [1] for cases where you''re not playing with objects. There you can set the content directly: text_area_tag("foo", content = "bar") //jarkko [1] http://api.rubyonrails.com/classes/ActionView/Helpers/ FormTagHelper.html#M000411 -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails