Ruby-on-rails 从 Rails 3 升级到 Rails 3.1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5968131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upgrading from Rails 3 to Rails 3.1
提问by user730569
How do you upgrade from Rails 3 to Rails 3.1 beta?
如何从 Rails 3 升级到 Rails 3.1 beta?
回答by Jeff Johnston
This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
在更新现有的 rails 3.0.8 项目时,这对我有用。你的旅费可能会改变...
Update the rails version specified in my Gemfile to use the latest release candidate:
更新我的 Gemfile 中指定的 rails 版本以使用最新的候选版本:
gem 'rails', '3.1.0.rc4'
Update the bundle:
更新捆绑包:
bundle update
Then update the project with the rake command:
然后使用 rake 命令更新项目:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
在樱桃采摘之后,虽然更改冲突,但我运行了所有测试并且它们通过了(是的!)。我重新启动了服务器,到目前为止一切似乎都很好。
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
但是,这还没有使用新的资产管道。我的意思是 javascript 和 css(或 sass)文件仍在以管道前的方式处理。据我了解,这是一个完全可行的选择。但当然,我想要新的优点,所以我相信接下来的步骤是包含和额外的 gems(例如,coffeescript、sass、uglifier 等),然后将旧文件迁移到 app/assets 目录。
I found some details about that are here:
我在这里找到了一些细节:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.
希望这是有帮助的。
回答by Jon M.
I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
我刚刚通过将 Gemfile 更改为从 3.0 升级到 3.1:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
我还在 config/environments/development.rb 中注释掉以下行
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
最后,确保在 config/application.rb 中启用资产管道
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
我不确定您是否已经阅读了发行说明http://weblog.rubyonrails.org/2011/4/21/jquery-new-default
回答by bor1s
回答by Mark Essel
Upgrading Rails
升级 Rails
Update: be cautious of using your system rake, as rake has been upgraded.
更新:请谨慎使用您的系统 rake,因为 rake 已升级。
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
确保您将为给定的 Rails 项目使用正确的耙子(源)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
我建议从一个新的应用程序开始,然后复制您的特定应用程序信息,同时将您的资源转换为新的资产/链轮格式。
An example
While converting an older rails 2.3.4 app to 3.0 I crashed and burned while changing one file at a time over within the project. Needless to say that was a flawed strategy, but I did learn a little along the way. I ended up skipping 3.0 and moving to 3.1beta1 with a fresh app, and copied my app and public folders in after getting the migrations right. That move had a couple of outstanding issues, the most important being that I didn't use rails edge for creating the new app (thanks for the tip RubyInside).
First snag the latest rails into an easy to reference location:
cd ~/goodtimes
git clonehttps://github.com/rails/rails.gitMy path includes a ~/Desktop/Dropbox/ so my code is available everywhere.
Then refer to that rails exec for building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
一个例子
在将旧的 rails 2.3.4 应用程序转换为 3.0 时,我在项目中一次更改一个文件时崩溃并烧毁。毋庸置疑,这是一个有缺陷的策略,但我确实在此过程中学到了一些东西。我最终跳过了 3.0 并使用新的应用程序移动到 3.1beta1,并在正确迁移后复制了我的应用程序和公共文件夹。此举有几个悬而未决的问题,最重要的是我没有使用 rails edge 创建新应用程序(感谢 RubyInside 的提示)。
首先将最新的 rails 插入一个易于参考的位置:
cd ~/goodtimes
git clonehttps://github.com/rails/rails.git我的路径包含一个 ~/Desktop/Dropbox/ 所以我的代码随处可用。
然后参考那个 rails exec 来构建一个新的应用程序:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
根据数据库的复杂性,您要么希望使用更改语法创建新迁移,要么将它们保留为:
class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :title t.text :body t.timestamps end end end
class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :title t.text :body t.timestamps end end end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
我在部署到 Heroku 时遇到了问题,但 RubyRacer gem 帮助解决了这个问题。这是一个简单的 Gem 文件示例:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
我怀疑会有社区实用程序来帮助您自动从旧版本的 Rails 迁移到 --edge。
References:
参考:
回答by twmills
I recommend updating your Gemfile to use edge rails. For example:
我建议更新您的 Gemfile 以使用边缘导轨。例如:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.
你可以在这里阅读更多http://pogodan.com/blog/2011/04/24/easy-edge-rails。
回答by Rushabh Ajay Hathi
http://railscasts.com/episodes/282-upgrading-to-rails-3-1
http://railscasts.com/episodes/282-upgrading-to-rails-3-1
this railscast might help !
这个 railscast 可能会有所帮助!
回答by abalogh
If i understood your question correctly this is how:
如果我正确理解你的问题,这是如何:
gem install rails --pre
回答by Josh Delsman
This is a pretty good guide which goes into some detail about installing Rails 3.1:
这是一个非常好的指南,其中详细介绍了安装 Rails 3.1:
回答by spnkr
Upgrading a rails 3.0.7 and 3.0.9 app using this guide worked for me
使用本指南升级 rails 3.0.7 和 3.0.9 应用程序对我有用
http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html
http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html
You can skip steps 3 and higher if you want--it will still work, although you won't be taking advantage of everything new in rails 3.1.
如果需要,您可以跳过第 3 步和更高的步骤——它仍然可以工作,尽管您不会利用 Rails 3.1 中的所有新功能。

