How to set a maximum length for text area in rails

how to set a maximum length for text area in rails

Have you checked out the API at http://api.rubyonrails.org/ ? It’s
really
handy and it’s free. Also there are quite a few good books you can get
to
learn Ruby on Rails. I highly recommend Agile Web D. with Rails
[2nd Edition].

RSL

Shiva S. wrote:

how to set a maximum length for text area in rails

Comment:

<%= f.text_area :comment, :cols => 30, :rows => 5 %>

When did forum members get so narky and unwilling to help? It would
have taken less characters to provide the answer than to give a lecture
on where to find it!

first to answer the OP:

a textarea element is an HTML element and there is no way to set the
maximum length of a textarea (you can set max length on a text input
element) other than using javascript tricks.

note: max length is not the same as setting rows/columns.

and second:

and as far as people getting narky (never heard that word before),
it’s most likely because, at least I have noticed, an ever increasing
number of questions that really have nothing to do with Rails (like
this one) or extremely simple questions that could be self-answered if
the poster only took the time to search the documentation or web.

This very same thing was (probably still is) an issue on the php
lists, irc channels and forums as more and more new users began to use
the language.

i personally see nothing wrong with pointing people in the right
direction as opposed to providing them with a free answer. a little
push toward self-help goes a long way. call it tough love!

Chris H. wrote:

first to answer the OP:

a textarea element is an HTML element and there is no way to set the
maximum length of a textarea (you can set max length on a text input
element) other than using javascript tricks.

note: max length is not the same as setting rows/columns.

I misunderstood the question it seems (unless the OP wants to clarify).

However, I disagree that it has nothing to do with Rails. If the poster
is using IRB then they may be using the text_area helper - is it not
possible that after looking through the dreaded
http://api.rubyonrails.org/ reference that the OP might think they have
missed it, not knowing what it might be called in the API, regardless of
whether it actually exists or not, or whether the equivalent function
exists in HTML? Rails being such an incredible framework, it would not
be unreasonable to expect that such a capability exists for this type of
field. I find the API most unhelpful, but I’m the kind of person that
learns faster from code examples. Searching my PDF references (I’ve
bought most of the books) an trawling Google for answers is how I tend
to find my answers - each to their own I guess. I agree however that
the Agile Web D. with Rails [2nd Edition] is an excellent
resource, along with Rails Recipes, Programming Ruby and SitePoint’s
Ruby on Rails book.

Tough love? I think more like self-righteous - “I had to find out the
hard way so so do you - is closer to the truth”. Sure there are people
out there that abuse the kind heartedness of others, but what happened
to benefit of the doubt. In my opinion, I think pointing someone at the
resources is fine, but you may as well provide the answer in the same
breath if you’re going to bother answering at all.

1 Like

As the saying goes “Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.”

Tough love probably wasn’t the best description. Consider it more of
a nudge in the right direction.

About the time that shiva shiva posted four very, VERY basic questions
within an hour or so which seemed to indicate he [or she] needed
something a
little more comprehensive than a simple reply about how to solve one
question. I really did mean it helpfully. Heck, I ask a hell of a lot of
questions sometimes. Moreso in the #rubyonrails channel but whatever. I
know
sometimes you really do need to RTFM. :confused:

RSL