Topic: text fields

Anybody know how to create a text field that will allow html formatting such as <br />

thanks,

Dan

Re: text fields

I meant textarea, not textfield.  Right now I have huge paragraphs, I need a way for people to break up the text the write in the textarea.

Dan

Re: text fields

I'm not sure I understand what you mean by "allow html formatting".  The text_area helper will create a textarea that will accept any format.

Re: text fields

I'm not quite sure what you're asking. Like thabenksta said, whatever you time in a text area will be saved into the database. If you are wanting so that people can make their own line breaks by hitting enter twice you might want to look at the simple_format  method.

Here is an example of it's use. Say you have someone type something that looks like this: http://www.dan-reedy.com/tutorials/misc/text_area_example.png

You'd save it normally without any additional modifications and when you want to display that information you'd use this code:

simple_format(@object.text_area)

Most code examples are usually pulled out of the air and not tested. Use at your own risk!

Re: text fields

Hello,

yes that is what I'm trying to do.  I just there to be a way to break up paragraphs and add things such as linksand images to text.

This is the form code

<%= form_tag :action => "comment", :id => @site %>
<%= text_area "comment", "body" %><br />
<%= submit_tag "Submit" %>

Would I put the simple_format method in the controller for the page that shows the information from that field?

Thanks,

Dan

Re: text fields

simple_format is a text helper that would go in your view.

Most code examples are usually pulled out of the air and not tested. Use at your own risk!

Re: text fields

You can also use textile or markdown to enable a richer display, but that's overkill compared to simple_format smile

vinnie - rails forum admin

Re: text fields

leonard31 wrote:

Hello,

yes that is what I'm trying to do.  I just there to be a way to break up paragraphs and add things such as linksand images to text.

This is the form code

<%= form_tag :action => "comment", :id => @site %>
<%= text_area "comment", "body" %><br />
<%= submit_tag "Submit" %>

Would I put the simple_format method in the controller for the page that shows the information from that field?

Thanks,

Dan

I think for linking to images you can just have people put in html.  Then when you display it somewhere else (not in a textarea) you can use the simple_format(@comment.body) and all the links should show up correctly.

Re: text fields

I just found out about auto_link too, which turns urls into links.