Skip to content

Instantly share code, notes, and snippets.

@techpeace
Created May 18, 2011 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techpeace/979165 to your computer and use it in GitHub Desktop.
Save techpeace/979165 to your computer and use it in GitHub Desktop.
A collection of scripts to automate some Rails 3 upgrade tasks
#!/usr/bin/env ruby
# Upgrades all files to use Rails.logger, rather than logger
Dir['app/**/*.*', 'config/**/*.*', 'lib/**/*.*'].each{ |filename|
data = File.read filename
File.open(filename,'w'){|f|
f.print data.gsub(/\slogger/, ' Rails.logger')
}
}
puts :Done
#!/usr/bin/env ruby
# Upgrades all files in child directories to the new erb snytax in Rails 3
# Does not upgrade custom concatination helpers
# See <http://asciicasts.com/episodes/208-erb-blocks-in-rails-3> for more info
# taken from <http://rbjl.net/24-upgrading-to-rails-3-obstacles-and-helper-scripts>
patterns =
%w|
fields_for
form_for
div_for
content_tag_for
field_set_tag
form_tag
remote_form_for
form_remote_for
form_remote_tag
| # don't forget to update remote helpers to hash option: remote => true
Dir['**/*.*'].each{ |filename|
data = File.read filename
File.open(filename,'w'){|f|
f.print data.gsub(/<%\s+(#{ patterns*'|' }).*(do|\{)/){
$&.sub '<%', '<%='
}
}
}
puts :Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment