Reputation: 2177
in Ruby on Rails: What is the difference between text_area
and text_area_tag
helpers?
More importantly, I would like to know which one is more suited to long HTML text input (specifically in my case, blog posts) ??
Upvotes: 0
Views: 4449
Reputation: 6786
if you use form_for
(always recommended) to render form then use
<%= f.text_area ....
otherwise you have to use
<%= text_area_tag ....
either will serve the same and no impact on input data (text) size
Upvotes: 0
Reputation: 3709
<%= f.text_area :attribute_name %>
<%= text_area_tag :any_name, :any_value %>
Upvotes: 0
Reputation: 47522
There are two types of form helpers: those that specifically work with model attributes and those that don‘t.
Ref text_area
which specifically work with model
text_area(:post, :body, :cols => 20, :rows => 40)
this will create following html
<textarea cols="20" rows="40" id="post_body" name="post[body]">
#{@post.body}
</textarea>
Ref text_area_tag
which doesn‘t rely on an Active Record objec
text_area_tag 'post'
will create following
<textarea id="post" name="post"></textarea>
Upvotes: 1
Reputation: 468
text_area set tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object) text_area(:post, :body, :cols => 20, :rows => 40) generate:
<textarea cols="20" rows="40" id="post_body" name="post[body]">
#{@post.body}
</textarea>
And text_area_tag 'post' generate
<textarea id="post" name="post"></textarea>
For more information, look: http://apidock.com/rails/ActionView/Helpers/FormTagHelper/text_area_tag http://apidock.com/rails/ActionView/Helpers/FormHelper/text_area
Upvotes: 0
Reputation: 51171
Difference is that if you use form_for
, pass ActiveRecord
object to it and pass, let's say, f
to block, it is much more convenient to use for example
<%= f.text_area :body %>
because it sets proper id, name and value automatically.
There's no difference between these helpers in handling long HTML text inputs, but if you want to use it for ActiveRecord
object form, you should use text_area
because, as I said, it's more convenient.
Upvotes: 1