Entries from December 2007 ↓

Javascript (RJS) Not Called In Ruby on Rails 2.0.2

After updating to Ruby on Rails 2.0.2 I ran into a problem where old code stopped working. The Ruby on Rails Weblog talks about new functionality to allow for us to use .html.erb instead of .rhtml and .js.erb instead of .rjs.

However it appears they may have broken something. In my project I have a controller with a ‘join’ method ending with this code:

respond_to do |format|
  format.html { render :layout => 'join' }
  format.js
end

My problem was that the join.rjs file was not called at all when the join action was called with text/javascript in the header (an AJAX call). Instead, the .html layout would always return.

Interestingly enough, renaming join.rjs to join.js.erb did allow for the file to be returned when I made an AJAX call, but RoR did not format it into Javascript.

My solution was to rename the join.rhtml to join.html.erb. Now the Javascript file gets properly executed with both .rjs and .js.erb.

I’m not sure under what exact conditions this bug pops up, but I know I have many other AJAX calls and many other .rhtml and .rjs files working just fine in other areas of my project. However, until this bug (if it really is a bug) is adequately dealt with, this workaround seems to do just fine.

I’ve posted a bug report here.

Edit: According to this forum post, while the original documentation is misleading, the desired format is .js.rjs. This should also solve this problem.

Script.aculo.us Patch – InPlaceEditor Incorrectly Determining Row Count

Recently in a project that my brother and I were working on we ran across a problem with the Ajax.InPlaceEditor resulting in the number of rows for the editor being incorrectly determined. Here you can see the area before it’s used:
Ajax.InPlaceEditor before clicking
When I clicked on the edit icon I got:
Ajax.InPlaceEditor bugged
Clearly not what I wanted. After fiddling with all the possible pieces and configurable parameters I finally traced it down to the source and realized there was a bug in the original code:

createEditField: function() {
var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {

Looking in the 2nd check of the if statement you see it’s checking for line breaks in “this.getText()”. It should have been checking the “text” variable it had just created above it. Changing that code to:

createEditField: function() {
var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
if (1 >= this.options.rows && !/\r|\n/.test(text)) {

…fixed the problem! Now when I click my InPlaceEditor I get:
Ajax.InPlaceEditor fixed

To share my fix I went to the Script.aculo.us page on Submitting Patches but unfortunately their instructions didn’t work right away for me.

Luckily Ryan Bates posted a Railscast called Contributing to Rails that had the right information I needed. Once I had successfully produced my diff file I submitted the patch to the Rails Trac.

Hooray! My first ever patch!

Aldenta and Glenn Fu Skydiving Adventure!

So my brother, John Ford (Aldenta), frequently sky dives and last weekend I went with him! Here’s the video:

He has so many great things to teach me! First it’s Ruby on Rails, then a little PHP. Then about how it’s a good idea to jump out of airplanes.

Thanks to Carolina Skydiving for an excellent first experience!