Skip to content

ruby on rails

Simply Jestful

Update: I'm using jester.js version 1.3.

Jester is basically ActiveResource for javascript. It's amazing. I love it! With almost no changes to my scaffold_resource generated controllers I was able to work on my models via javascript in my web browser.

All I had to do was download the javascript and put it in public/javascripts/

I put this in my layout: <%= javascript_include_tag 'jester.js' %>

Then I was able to do this in Firebug:

>>> Base.model('User')
>>> Base.model('Comment')
>>> c = Comment.create({comment: 'i love jester'})
POST http://localhost:3000/comments.xml (381ms)prototype.js (line 866)
Object _name=Comment _format=xml _singular=comment
>>> c.id
12
>>> c.user
Object _name=User _format=xml _singular=user _plural=users
>>> c.user.display_name
"Mike"

Use XML, not JSON. The Rails implementation of .to_json() is not as fully featured as .to_xml().

This patch was accepted into core in June. I used it to patch my rails-1.2.3 installation. It stops the following from failing:

format.xml  { render :xml => @post.to_xml(:include => :comments, :methods => [:obfuscated_email]) }

Jester is documented in a series of release announcement blog posts. I recommend reading them in order.

Vim Syntax Highlighting for Rails

A couple of days I updated the font settings in terminal.app on my mac. It's now in line with textmate using Anti-Aliased 14 point DejaVu Sans mono.

Terminal Window Settings

I think you'll agree, it's pretty.

Vim Syntax Highlighting

Now I want to get my vim syntax highlighting to mirror that in Textmate. My vim doesn't currently understand rhtml. I also want it to use the same colorscheme (Sunburst) that my Textmate is using.Who will join my quest?

update big response from the lists.

Install rails.vim so it will recognize .rhtml files. It also touts "easy file navigation, enhanced syntax highlighting, and more"

Install vividchalk.vim, a colorscheme like Vibrant Ink for Textmate. Apparently it has a 16 color mode for remote terminal support. I still want to find Sunburst but at least I could always make one based on this.

The Rails Wiki has a page on HowtoUseVimWithRails

Stay tuned!

Enable SSH agent forwarding for Capistrano

Having to repeatedly enter passwords is a drag. And enabling password based SSH login to your SVN servers is a security risk. So I'm pretty excited that Chris Andrews implemented SSH agent forwarding into net-ssh-1.1.0.

Update to the latest version of net-ssh with:

$ sudo gem update net-ssh

To enable it, put the following into your ~/.caprc:

ssh_options[:forward_agent] = true

This stopped me getting prompted for a password by my subversion every time I ran 'cap deploy'.

Integrating Wordpress into a Ruby on Rails site

The first question you'll probably ask is why I didn't go with typo or mephisto. While I have to admit I haven't tried them myself, I decided to use WordPress based on the maturity of the software and size of the userbase. I think this is a pragmatic choice for a piece of software I want to use on my site.

WordPress has a nice feature packed management interface. It also supports themes and I found I could customize it to fit in with my site without editing any of the files that come with the main distribution. This means I can automate upgrading of WordPress when future versions (with security fixes) are released.