Learning Ruby on Rails Day 40

Where did time go? Last time I added an entry to my Learning Ruby on Rails journal, it was May 6th. Today is October 30th. There may have been 40 days of learning between then and now. I am back into it — is what matters. Teaching myself Ruby on Rails has become a sort of yoga practice in my life. It feels mostly good and places a nice comfy shield between all the bad noise in my life and my easily-troubled head.

I have set each chapter of a book I have yet to finish reading as 'action' in my Action Method. The book is Simply Rails 2. I am plowing along. The grass is green and cut short and clean. Patrick Lenz is a fantastic writer. Thanks to him, the pasture smells great. Actually, I smelled something funny tonight. I got back into wrapping my head around RJS templates.

They are written in Ruby. Like *.html.erb templates, they are stored in the views folder. They have the extension .js.rjs because once the Rails engine is done with them JavaScript is returned to the browser. Ah, I am not explaining well. Good definition found in Foundation Rails 2: “RJS is Rails’s solution for generating JavaScript code using Ruby. [It] is a server-side solution for generating dynamic responses to AJAX requests without having to resort to writing [...] JavaScript. [...] RJS code [...] resides in specially named RJS templates that can be found in the same directories as our traditional HTML views. However, whereas our standard view template would be named something like index.html.erb, the RJS template for the same action would be named index.js.rjs. So you can see it [follows] the same naming convention with the first word [being] the action it’s associated to, the second [word] representing the type of content that we’re returning (js for JavaScript in this instance), and the final [word] representing the rendering engine that is used to parse the template (RJS for this).”

I usually install the vendor plugin jRails to get rid of Prototype and when I build any new application. There exists a jRails gem now, but I didn't have much success with it.

jRails, FYI, has moved to github. “ennerchi” and “aaronchi” are the same guy. To install jRails:
ruby script/plugin install git://

Not sure whose fault it is, probably that of jRails, but I'm sending the authenticity_token twice with every Ajax request.


I am using the form_remote_tag helper:

<% form_remote_tag :url => story_votes_path(@story) do %>
  <p><%= submit_tag 'Shove This' %></p>
<% end %>

The following HTML is generated:

<form action="/stories/5-google/votes" method="post" 
onsubmit="jQuery.ajax({ data:jQuery.param(jQuery(this).serializeArray()) +
'&amp;authenticity_token=' + encodeURIComponent('zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok='),
dataType:'script', type:'post', url:'/stories/5-google/votes'}); return false;">
  <div style="margin:0;padding:0">
    <input name="authenticity_token" type="hidden"
 value="zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok=" /></div>
  <p><input name="commit" type="submit" value="Shove This" /></p></form>

The form already contains a hidden input field that stores the authenticity token (this protects against forgery). jQuery serializes the form, hence serializes that token, but then... it adds it again! That's not right.

data: jQuery.param(jQuery(this).serializeArray()) + '&amp;authenticity_token=' +
encodeURIComponent('zctxjCg1I5w9LTgk7YvvSEsvAFN4Km+FzvsJuU2Jrok='), ...

The following code should suffice:

data: jQuery.param(jQuery(this).serializeArray()), ....


Also, RJS requires some getting used to for me. Seems weird to have an Ajax request return JavaScript to execute, rather than JSON, or text data, or XML, or nothing. I usually use callback functions when doing Ajax: when the data is returned, if any, some JavaScript function is run, doing whatever to the page. There's really different shit happening here, although results are the same of course.

text/javascript; charset=utf-8

The JavaScript returned to the browser is a big Try and Catch. If a JavaScript error occurs, an alert box tells you what went wrong.

try {
jQuery("#vote-score").html("Score: 112");
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('jQuery(\"#vote-score\").html(\"Score: 112\");
\njQuery(\"#vote-score\").effect(\'highlight\',{},2000);'); throw e }

Eh, this looks a bit convoluted:


Couldn't we just use this — not sure:


Unobtrusive jQuery

I prefer unobtrusive jQuery just because it's more manageable. I also like to write my own JavaScript — or at least be able to edit it. Ryan Bates shows here how to use jQuery without jRails. No helper functions. No JavaScript generated for you. Ryan Bates uses Ajax requests that return JavaScript as does jRails. But the JavaScript that's returned is stored, this time, in a .js.erb template.

The form on the page is submitted asynchronously thanks to some jQuery added to application.js. (Shown below.) Ryan Bates uses a simple call. And he does uses jQuery(this).serialize! I may try to modify my Shovell app (the book project in Simply Rails 2) to use a .js.erb template. What we're comfortable with may not be the better way, though. If I get used to using RJS templates, I may learn to love them. Not sure.

How to use jQuery with Rails - Screencast by Ryan Bates

Last edited by Caroline Schnapp about 7 years ago.



Interesting article. Too bad that there are not to many similar articles. But I found all and even more here

Your post made me involved in Learning Ruby

I didn't know those files have extensions .jrs and .rjs thanks for this interesting information. Now I'm writing my college paper and I was looking for smth like this to relax my mind but after this article I decided to order my papers on that is easier than to sit and write it througout the night!


Hello, i feel that i saw you visited my web site thus i came to “return the favor”.I'm attempting to realize things to enhance my site!I suppose its alright to use a few of your ideas!!

Happy New Year 2016 Wallpapers

Get Happy New Year 2016 Wallpapers free download.


thank for information brother, is the nice nice amazing post you ready ? im ready be happy :)
suplemen patah tulang dan obat alami kencing nanah

wan mo dari cikiwan cikicu

wan mo dari cikiwan cikicu

Does Ruby Classes are available on Google Chromecast ?

Just Set up Chromecast in my TV. Does ruby classes are available on TV channels


There are so many comments here that are really interesting and conducive to me thanks for sharing a link especially for sharing this blog.

Real Weddings

Good information and easy to understend.
Real Weddings

neviditelna podprsenka

Nice one, there's truly some sensible points on this website a number of my readers might realize this useful; i have to send a link, several thanks.

Future residents will be

Future residents will be able to walk to the existing Bartley MRT in the Circle Line. With such a short drive to the city area as well as the orchard and bugis area, entertainment for your love ones and family will come at a stone’s throw away.
gmod free to play

chromecast set up and Support

For chromecast set up and Chromecast Support, I provide teaching and help to those who use chromecast and facing technical problems in usage. Ruby is currently demand for programming but it will R.I.P future as Google hide secret weapon of programming call Android development. App are possible with the help of Android and google planning to remove Java Courses from Android very soon. Go (programming language) is set in pipeline to fire. Best thing that google can't beat Ruby is it's security reach. Much stronger then PHP and .net.

Best wishes to Ruby Developers !!

It is hard to have such

It is hard to have such website for itunes gift cards.


Thank you for your very informative blog article. I wrote my master thesis about this and I came basically to the same conclusion. Keep up the good work with your cheat field blog!

अमीषा पटेल

Very interesting! By the way, you can order excellent papers online

hot bollywood

Good information and easy to understend

Learn Ruby via chromecast within two month


I know ruby is bit tough language. How much time it would take me to get expert. I got an app in my android phone. which gives tutorial classes online. I use chromecast setup with my big screen tv. but problem is, how should i record them.

Kindle Unlimited Is Filled With 3,000 Page Garbage Books Which S

I continue to be impressed by the high level of Blogs that y'all provide. It's fabulous!

Apple iphone 3G 8GB Full Specs & Price in Pakistan

Find latest Apple iphone 3G 8GB Full Specs & Price in Pakistan. Apple iphone 3G Price in Pakistan free updated

very nice dude. Clash Royale

very nice dude.

Clash Royale Triche


Very good article thanks
shivling in makka
shiva mantra
Shiva AArti
keep Writing

Mathura Temple

great keep writing
Vrindavan Chandrodaya Temple


Great and Nice Keep Update Nice Website
lord shiva
shivling in makka


I opted for no credit check loans from Oyster Loans to resolve the unforeseen expenses. These loans are easy to derive and I got a chance to reclaim the financial stability, without much of any inconvenience.
no credit check loans


I opted for no credit check loans from Oyster Loans to resolve the unforeseen expenses. These loans are easy to derive and I got a chance to reclaim the financial stability, without much of any inconvenience.
no credit check loans

Java Assignment Help I need

Java Assignment Help
I need to offer a go-ahead for such an educational post....its truly astonishing

This is an amazing type of

This is an amazing type of post.
Tea and Coffee

Thank you for topic

Thank you 11heavens i enjoyed with your topic ... Good luck


Compare best web hosting and plans based on reviews, features and price. Get your website. Web Hosting. Our experts have compared the best web hosting providers. Read the best web hosting reviews and choose the most reliable web hosting.

loan for unemployed

The fact that you are taking so much of pain to shed some lights on the relevant subject is indeed commendable. As of now I on loans for unemployed and your ideas truly inspire me .Thanks Again- Adios for now.

Love Commands

No running back and forth from your home to the shop to your home to the shop to your home to the shop comparing colours and samples
Love Commands

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <css> <html> <javascript> <mysql> <php> <span> <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <javascript>, <mysql>, <php>, <rails>, <ruby>.

More information about formatting options

I have to wonder if you're a human spammer or a machine, or less likely someone who cares to leave his or her thoughts behind.