简体   繁体   English

管理许多不同版本的Ruby on Rails应用程序

[英]Managing many Ruby on Rails applications of different versions

I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. 我正在使用AWDR书籍学习Ruby on Rails,并且必须具体说明我在本地计算机上运行的Rails和Ruby版本。 I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here . 我刚才发现我需要推出红宝石1.8.7回红宝石1.8.6 这里 I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily. 我还需要回滚Rails以支持scaffold方法,因此我可以轻松地开始本教程。

My question is: When I start contracting, developing and deploying projects in the real world, how am I going to manage all these different versions? 我的问题是:当我开始在现实世界中承包,开发和部署项目时,我将如何管理所有这些不同的版本?

It looks to me like Rail's low tolerance for legacy code negates its ease of use philosophy! 在我看来,Rail对遗留代码的低容忍度否定了其易用性理念! But I'm sure I'll grow to appreciate RoR. 但是我敢肯定,我会越来越喜欢RoR。

As for Rails, What you can do is freezing your version, for example: 至于Rails,您可以做的是冻结您的版本,例如:

  1. Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.2.2 确保安装正确的Rails版本,假设您想要版本2.2.2: gem install rails v = 2.2.2
  2. Freeze and pack Rails with the project itself : rake rails:freeze:edge RELEASE=2.2.2 使用项目本身冻结和打包Rails: rake rails:freeze:edge RELEASE=2.2.2

Now you will find Rails packed inside the vendor folder of your project, so you don't have to install Rails on the deploying machine. 现在,您将在项目的vendor文件夹中找到Rails,因此不必在部署机器上安装Rails。

And for Ruby, I like Ruby Version Manager (RVM), the easiest way to manage Ruby versions. 对于Ruby,我喜欢Ruby Version Manager (RVM),这是管理Ruby版本的最简单方法。

The latest version of Agile Web is written for 2.2.2 I believe. 我相信,最新版本的Agile Web是针对2.2.2编写的。 For this basic app they walk you through I'm very certain it should work with 2.3.x 对于这个基本的应用程序,他们会引导您完成操作,我非常确定它应可与2.3.x一起使用

The answer to the question for how you keep up is that you update your apps as needed and read the api and Changleogs to find out what has changed and fix the stuff that upgrades break. 关于您如何跟上进度的问题的答案是,您可以根据需要更新应用程序,并阅读api和Changleogs,以查找已更改的内容并修复升级失败的内容。 A great way to help with this is having a good test suite with good test coverage. 解决此问题的一种好方法是拥有一个具有良好测试覆盖范围的良好测试套件。

RubyGems is Ruby's package manager. RubyGems是Ruby的软件包管理器。 You can install as many versions of gems (packages) as you want. 您可以根据需要安装任意数量的gem(程序包)。 You can install the latest by running sudo gem install rails (at the moment it will install 2.3.5). 您可以通过运行sudo gem install rails安装最新版本(目前它将安装2.3.5)。 If you need 2.2.2, specify that with the -v or --version option: sudo gem install rails --version 2.2.2 . 如果需要2.2.2,请使用-v--version选项进行指定: sudo gem install rails --version 2.2.2 Rails also installs a binary (yes, I know it's not really a binary file), rails , which generates a project. Rails还安装了一个二进制文件(是的,我知道它不是二进制文件), rails ,它会生成一个项目。 Because you have several versions of the gem, you need to control which binary gets called. 因为您有多个版本的gem,所以您需要控制调用哪个二进制文件。 When you install the rails gem, RubyGems puts a file in it's bin/ dir, which is a "link" to the real rails binary. 当您安装rails gem时,RubyGems会将文件放在bin/ dir中,这是指向实际rails二进制文件的“链接”。 That is the one you "call" when you say rails on the command line. 当您在命令行上说rails时,这就是您“呼叫”的那个。 However, all of the rubygems "link" binaries accept a parameter of it's own, which is what version you want to use. 但是,所有rubygems“链接”二进制文件都接受自己的参数,这是您要使用的版本。 You would use the 2.2.2 rails binary like this: 您将像这样使用2.2.2 rails二进制文件:

rails _2.2.2_ my_project

I think the default is to use the most recent version, so if you want to use the most recent version, do this: 我认为默认值是使用最新版本,因此,如果要使用最新版本,请执行以下操作:

rails myproject

However, I see that you use 2.2.2 to get access to the scaffold method. 但是,我看到您使用2.2.2来访问scaffold方法。 I would strongly suggest you not to use that method, there's a reason for removing it. 我强烈建议您不要使用该方法,有理由将其删除。 The scaffold method hides code, and makes customization hard. scaffold方法隐藏代码,并使自定义变得困难。 Instead, use the scaffold generator: 而是使用脚手架生成器:

./script/generate scaffold --help

Good luck on your future rails adventures! 祝您未来的冒险之旅好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM