- The syntax is clean and it’s often less code than pure javscript.
- When writing this function, I can mix in powerful Ruby constructs.
- It’s consistent with the other RJS in the project.
- I automatically get the function wrapped up in a CDATA tag.
- I automatically get exceptions handled by giving me an alert of the problem.
- My rails views look cleaner.
Here’s an example from a rails view (new.erb):
1 2 3 4 5 6
So where’d this define_js_function method come from? I added it to ApplicationHelper. Here it is:
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4