开发者

How to upgrade a Rails 3.0 app to Rails 3.1?

I have a Rails 3.0 app (technically 3.0.7) which I would like to upgrade to Rails 3.1 to make use of the new asset pipeline and other fancy new features. What is the best approach to doing this? Should I use the rails new generator, then copy everything from my old app over to the new one? What about 开发者_如何学JAVAversion control? I already have my old app using Git.


Just upgraded one of my apps from 3.0.9 to 3.1.0, here's my approach, your mileage might vary:

Edit Gemfile, change Rails gem version

gem 'rails', '3.1.0'

Also adds new gems introduced in 3.1.0

group :assets do
  gem 'sass-rails', "~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end
gem 'jquery-rails'

run bundle update rails

Then run rake rails:update and resolve conflicts.

Move your css/javascript/images etc to app/assets folder, make sure there's an application.js and an application.css file (you might want to take a look at those two from newly created 3.1.0 projects)

Include css/javascript links in your layout file like this

<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>


Get familiar with rails 3.1, here are the resources: http://jasonrudolph.com/blog/2011/06/06/helpful-resources-for-upgrading-to-rails-3-1/

The most important thing are your current test, make sure you have a good test coverage of your 3.0 app before you start.


Create a new branch in your Git repo.

Take a look at the Rails 3.1 Example Apps if you are using Devise, RSpec or Cucumber because they will give you a good working reference implementation. If not, just use rails new to create a simple Rails 3.1 app.

Then use a file compare tool (such as FileMerge or Changes on Mac OS X) to identify where the Rails 3.1 code differs from your 3.0 app.


I have just done this today with an app from 3.0.9 Take a look at this blog, its pretty simple.

http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html

Its just a matter of changing gem file, a few config variables,moving a few assets and creating some css and js manifest files, shouldn't take more than an hour.


copy this gems to your gem file replacing the old once gem 'rails', '3.1.0'

group :assets do
  gem 'sass-rails', "~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

All you have to do is run rake rails:update

you can also run rake -T to see some cool rake task that you would need

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜