about me

I'm a 36'ish year old web application developer from South Portland, Maine. I love meeting fellow techies, drop me a line if you want to talk shop.

Categories

jQuery helpers for Rails 3.0.0.beta

Posted on 02/08/2010 at 01:58 PM

I’ve just ported the unobtrusive javascript helpers in Rails 3 from Prototype to jQuery-1.4.1, but I haven’t tested it to work with earlier versions of jQuery yet. Let me know if you find this useful or have any issues installing the gem.

For those that don’t know, Rails 3 now makes use of HTML5 custom data attributes on the DOM instead of generating javascript inline when using it’s built in javascript helpers. If you’re not planning to use HTML5 in your app, you might benefit from another plugin I wrote called js-data-helper.

Thanks to @technicalpickles for helping me package this up as a gem.

The code is on Github.
http://github.com/CodeOfficer/jquery-helpers-for-rails3

The gem is on Gemcutter
http://gemcutter.org/gems/jquery_helpers

Install:
  (sudo) gem install jquery_helpers

Usage:
  rails generate jquery_helpers  [options]

Runtime options:
  -f, [--force]    # Overwrite files that already exist
  -p, [--pretend]  # Run but do not make any changes
  -q, [--quiet]    # Supress status output
  -s, [--skip]     # Skip files that already exist

Description:
    A port of the unobtrusive Prototype helpers in Rails 3 to jQuery

Example:
    ./script/generate jquery_helpers

    This will create:
        public/javascripts/jquery.rails.js
        public/javascripts/jquery.rails.min.js

Don’t forget to include ‘jquery.rails.js’ in your layout along with jQuery.

UPDATE May 11, 2010:
Rails has their own port to jQuery that is better maintained now.
http://github.com/rails/jquery-ujs

8 Comments

Comment #1 by webPragmatist  on  02/08  at  02:42 PM

Checkin’ sum spellz…
no rly. FIRST!

Comment #2 by Sergio Rivas  on  02/13  at  09:51 AM

I have installed the gem with

gem install jquery_helpers

When I go to generate the helpers, its doesn’t work…

rails generate jquery_helpers

$ Could not find generator jquery_helpers.

Can you help me?

Comment #3 by CodeOfficer  on  02/13  at  10:29 AM

@sergio, make sure you bundle your gems first. Your rails 3 app wont be able to use the generator of this gem until you’ve bundled it. Use:

bundle pack

Comment #4 by Sergio Rivas  on  02/13  at  10:43 AM

Thanks! As you say:

I just add this line:

gem “jquery_helpers”

to Gemfile And Works!

Comment #5 by Strock  on  05/11  at  01:21 AM

Hello. After installation of jquery_helpers gem, which also installs rails-3.0.0.beta and other dependencies, while rails-3.0.0.beta3 is already installed, “rails generate jquery_helpers” command fails with message “/usr/local/lib/site_ruby/1.8/rubygems.rb:334:in `bin_path’: can’t find executable rails for railties-3.0.0.beta3 (Gem::Exception)”. What am I doing wrong?

Comment #6 by CodeOfficer  on  05/11  at  07:54 AM

@strock Enough time has passed since I wrote this gem that Rails has released their own code for the unobtrusive jquery helpers. Check it out here:

http://github.com/rails/jquery-ujs

Comment #7 by Strock  on  05/11  at  09:01 AM

Yeap, already used that, combined with jrails. Works fine for now! It seems to me, though, that dependencies in your gem are written strongly for rails-3.0.0.beta, not something like “>= rails-3.0.0.beta”, and that broke things up.

Comment #8 by CodeOfficer  on  05/11  at  09:09 AM

Yep thats exactly what it is. I should pull it down though so no-one uses it. After Rails came out with their own port there wasn’t much point.

Leave a comment?

Please use Pastie or Gist if you need to write code in your comments.

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?

Please enter the word you see in the image below:


RailsConf 2008 Often times I will release code for free or go that extra distance to help others online. If my skills were useful to you, please consider a small donation. Thank you very much.

recommend me!

Search

You Can Find Me

@ github.com
@ twitter.com
@ calendaraboutnothing

My Wishlists

@ Amazon.com

My Other Sites

Foundation's Edge, RJones Family, We're Not.com (only for staging), Ailee Jones (same as rjones for now)

Friends of Mine

Aaron, Barnaby, Brian, Chris, Dirk, Frank, Four, Justin, Matt, Mike, Monty, Paul, Sean, Travis

IRC Hangouts

I can usually be found lounging on irc.freenode.net while I work, on the following channels: #fauna, #github, #hello-heroku, #jquery, #passenger, #ruby, #rubyonrails, #slicehost, #sproutcore, #textmate, #werenot.