Jonathan del Strother
2006-Jul-04 20:48 UTC
[Rails] Best way of storing and recalling data for display?
I want to store a number of snippets of html representing messages, and display them in response to user events. I''m currently storing them in a javascript array at page-load time, then display individual snippets using Element.update(). The message array can get extra messages added to it following an ajax call. The set up looks something like this: <script type="text/javascript" charset="utf-8"> <% @messages.each do |msg| html_insert = escape_javascript( "<span class=\"messageType\">#{msg.message_type}</span> <span class=\"messageFieldLabel\">From:</span><span class= \"messageField\">#{h msg.from}</span> <span class=\"messageFieldLabel\">Subject:</span><span class= \"messageField\"><strong>#{h msg.subject}</strong></span> <span class=\"messageFieldLabel\">Date:</span><span class= \"messageField\">#{h msg.sent_at}</span> <span>#{(h msg.body).gsub(/\n/, "<br/>")}</span>''") %> AppController.addMessage(<%=msg.id%>,"<%=html_insert%>"); //store the message for later retrieval <% end %> </script> ...which works, but it just feels so...unpleasant. Embedding this big javascript stringy mess in the page source, all those escape characters... there must be a cleaner way of doing this. Any suggestions? I''m sure there was a blog posting recently about embedding stuff like this within a .js file generated by erb (rather than the static .js in /public/javascripts) - but I can''t find it now. Any suggestions what that might have been? Jon -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2114 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060704/7892addc/smime.bin
Maybe Matching Threads
- Making new Ajax.Updater within a previous Ajax.Updater call
- Component using
- How switching global layout (application.rthml <or> custom.rhtml)
- help with recalling data points in a specific region of the plot
- recalling different data frames (the way you do in Excel VB)