开发者

Text Field in Rails whose size increases dynamically

I am trying to implement a groups feature similar to that of Facebook in my project. I am using Rails 2.0.2 and Ruby 1.8.7 for project specific purposes. I am using Ubuntu 10.04 OS.

I want to implement a text field for the Discussion Topic and the corresponding comments whose size increases dynamically as there is an increase in the size of the text.

In Rails while defining your migrations there is a way of having a huge text area for开发者_如何学Go attributes like Description, the code for it is some thing like this in the migration t.text :description .

Now this would not look really good in most cases where the discussion topics and the corresponding comments aren't so big.

Considering this, is there any other way around it wherein the the text field can by dynamically controlled based on the size of the text entered during run time. If yes kindly guide me on how can I go about the same.

Also , what type of attribute would I have to name it as for the same.

Any inputs/suggestions on this is highly appreciated..

Thank you...:)


Okay, first I should point out that the t.text in the migrations file is not necessarily the reason why in your view you get a large text area. t.text just informs the rails generator to create a column in the given table that can store large textual data.

But if you use scaffolding, the generated view will use f.text_area to render the corresponding field on the screen and that's why it appears large.

Now if you want to keep the text area small and let it grow according to its content, you need to use JavaScript. And my favorite JavaScript library/framrwork is jQuery and if you are familiar with jQuery you can the use a jQuery plugin like the jQuery expanding text area (demo) to achieve that. However Rails 2 uses Prototype/Scriptaculous by default and if you want to stick with that, then you can use a similar Prototype plugin such as this one or write something from scratch like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜