Here is my approach to quickly enabling Unobtrusive Javascript support for your Rails application, using jQuery:
- Create a Rails application without Prototype support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters$ rails new myCommentsApp --skip-prototype - Edit your config/application.rb to include the latest jQuery and the Rails UJS adapter for jQuery:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersconfig.action_view.javascript_expansions[:defaults] = %w(http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js rails application)
Update (May 4th) for jQuery 1.6:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersconfig.action_view.javascript_expansions[:defaults] = %w(http://code.jquery.com/jquery-1.6.min.js rails application) - ...oh, I said 3 steps, right!
Just continue building your application; here's an example: YouTube-like-comments.
Or...
ReplyDelete1. put 'jquery-rails' in your Gemfile
2. run 'bundle install'
3. run 'rails g jquery:install'
Tip you can pass --ui to the generator command to install jquery-ui too.
Yes, this are 3 steps and you cheat to make it in two (1.5- Download rails ujs adapter for jquery)
I like this approach better.
He he, thanks for the tip! ;o)
ReplyDelete