Get updates

Archive for March, 2007

Scott Q&A: How to use plain JavaScript in RJS templates

What’s all the fuss over RJS templates for Rails? JavaScript is not, in my opinion, the dirty/scary/tedious or otherwise lame language some people seem to think it is. I actually enjoy writing JavaScript objects, and currently the codebase of my hierarchical list manager app contains about as much JavaScript as Ruby code.

Despite my JavaScript predilection (or because of it), I am happy to work with RJS templates. Why? Because they make working with JavaScript (and client-side capabilities JavaScript offers) in Rails a whole lot easier. A lot of what makes Rails really fun is stuff like the easy integration of Ajax and JavaScript for the UI, such as Scriptaculous.

RJS templates make it a snap to respond to an Ajax request with much more than just an update for a single element, through a number of wrapper functions that generate JavaScript for you. Yet sometimes you’ll still want to interact with your own custom JavaScript functions and objects.

Question: How can plain JavaScript be used inside RJS templates?

Continue Reading…

3DM Design is where Scott Drake publishes thoughts on programming web applications in JavaScript and Ruby.

Fatal error: Uncaught Error: Call to undefined function ereg_replace() in /home/dmetro/ Stack trace: #0 /home/dmetro/ akpc_is_searcher() #1 /home/dmetro/ akpc_api_footer_javascript('') #2 /home/dmetro/ WP_Hook->apply_filters(NULL, Array) #3 /home/dmetro/ WP_Hook->do_action(Array) #4 /home/dmetro/ do_action('wp_footer') #5 /home/dmetro/ wp_footer() #6 /home/dmetro/ require_once('/home/dmetro/3d...') #7 /home/dmetro/ load_template('/home/dmetro/3d...', true) #8 /home/dmetro/ locate_t in /home/dmetro/ on line 2531