Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # in the model
- self.js_stub
- require 'ostruct'
- OpenStruct.new(:title => '$TITLE', :isbn => '$ISBN', :image_url => '$URL', :authors => '$AUTHORS', :published_on => '$PUBLISHED_ON', :pages => '$PAGES')
- end
- # in some helper
- def render_javascript(name, locals=nil)
- escape_javascript render(:partial => name, :locals => locals).gsub(/\n\s*/, '')
- end
- # in the template
- <% javascript_tag do -%>
- var TEMPLATES = {
- book_cover: function(book) {
- return '<%= render_javascript 'books/book', :book => Book.js_stub %>'.
- replace(/\$TITLE/g, book.title).
- replace(/\$ISBN/g, book.isbn).
- replace(/\$URL/g, book.image_url);
- }
- };
- <% end -%>
Add Comment
Please, Sign In to add comment