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.
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
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?
@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
Thanks! As you say:
I just add this line:
gem “jquery_helpers”
to Gemfile And Works!
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?
@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:
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.
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.
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.
@ github.com
@ twitter.com
@ calendaraboutnothing
Foundation's Edge, RJones Family, We're Not.com (only for staging), Ailee Jones (same as rjones for now)
Aaron, Barnaby, Brian, Chris, Dirk, Frank, Four, Justin, Matt, Mike, Monty, Paul, Sean, Travis
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.
Checkin’ sum spellz…
no rly. FIRST!