Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rake task to setup a Rails 3 app for jQuery instead of Prototype
# Rails 3 jQuery Install Rakefile
# by Aaron Kalin
# Compiled from
# Note: this assumes you use git, if not then use the optional usage
# Usage: rake install_query
# Optional usage: rake install_jquery[nogit]
# Install: drop this file into lib/tasks, then run rake install_jquery
desc "replace prototype with jQuery (via git)"
task :install_jquery, :nogit do |t, args|
puts "Ripping out Prototype"
# Prototype files to remove
proto = ["public/javascripts/prototype.js",
"public/javascripts/controls.js"].join(" ")
# check for git
if args.nogit
remove = "rm"
remove = "git rm"
# Remove files
system "#{remove} #{proto}"
# Setup jQuery
puts "Downloading jQuery"
system "curl -L > public/javascripts/jquery.js"
system "curl -L > public/javascripts/rails.js"
# Install initializer
puts "Installing Initializer"
assetstring = %{
module ActionView::Helpers::AssetTagHelper
JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)
}"config/initializers/jquery.rb", "w") do |f|
f.write assetstring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment