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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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 databaseThe 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>" http://api.rubyonrails.org/classes/ActionView/Helpers/ TextHelper.html#M000513 -- Jeffrey Hardy (packagethief) http://unspace.ca http://re.visioni.st http://quotedprintable.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---