问题
I'd like to now how to handle multiple markup languages (textile, markdown and bbcode) in a text area using ruby on rails 3.
The user would be able to select the markup language he/she wants to use, write in that language, and then the view would render the text using the markup language selected by the user.
I'm currently handling that storing a field for each text area, but I'm sure there are better ways and I'd love to hear your opinions and come up with a better way.
回答1:
When are you processing the markup the user enters? Are they ever going to need to re-retrieve it?
I'd do this by having three attributes on my model: original_text
, markup_language
(which is either textile, markdown, or bbcode), and rendered_text
. When the user hit save, I'd save the text and use the value they provided for markup_language
to figure out what renderer to use to store it into rendered_text
.
来源:https://stackoverflow.com/questions/4620690/handling-more-than-one-markup-language-in-a-text-area