Text entry recipe

Wondering if there is a Rails recipe out there to help me handle a large amount of text entry.

Basically, the user can enter text with variable spacing (extra spaces, newlines). I don't want to allow HTML or other formatting at this time. Just basic text entry. Of course, special characters need to translate properly.

I created the column to store this value in mySQL using migration's "text" field type.

I save what is entered. It looks pretty normal when browsing the database. However, when displaying the value back out to the screen, all spacing is lost, naturally. I imagine I'll have to do some encoding of space and newline characters before putting the text entry field value to the database. But I figured I'd check with the community because it'd seem there'd be a better way, perhaps with a helper I'm unaware of.

bjhess wrote:

Wondering if there is a Rails recipe out there to help me handle a large amount of text entry.

Basically, the user can enter text with variable spacing (extra spaces, newlines). I don't want to allow HTML or other formatting at this time. Just basic text entry. Of course, special characters need to translate properly.

I created the column to store this value in mySQL using migration's "text" field type.

I save what is entered. It looks pretty normal when browsing the database. However, when displaying the value back out to the screen, all spacing is lost, naturally. I imagine I'll have to do some encoding of space and newline characters before putting the text entry field value to the database. But I figured I'd check with the community because it'd seem there'd be a better way, perhaps with a helper I'm unaware of.

You could use the 'textilize' function to format it.

You will need the RedCloth Gem

_Kevin

However, when displaying the value back out to the screen, all spacing is lost, naturally. I imagine I'll have to do some encoding of space and newline characters before putting the text entry field value to the database

The simple_format() helper is good for simple cases like this. It merely converts new lines to break tags and paragraphs as appropriate. You can store your text in the database as normal, formatting it only as required for display:

simple_format('some text') #=> "<p>some text</p>"

Thanks, Jeffrey. simple_format did exactly what I needed. Now I have to make sure any user-entered HTML code gets filtered out or ignored...