What's the point of freezing your Rails version/gems?

情到浓时终转凉″ 提交于 2020-01-19 11:12:04

问题


What does that mean?

In the instructions for a project, it said to "freeze the Rails gems". Is that different from freezing the Rails version?

What's freezing about?


回答1:


If one of the authors of a gem you use introduce a new version of the gem, there is a possibility the new version introduces backwards incompatible changes that would break your code.

Freezing a gem puts it into the vendor folder of your application, and it will not be automatically updated on its own. Rails will use this version of the gem instead.

This allows you to update the gem on your system for other apps, while having your sole app use the version of the gem that you have always been working with, and therefore is stable.

This applies to the rails gem itself as well, as newer versions of rails might eventually cause something in your app to break, freezing it will prevent the system wide update (and, once again, allows you to update other apps on your machine, while leaving the app you freeze rails in at that version number.




回答2:


I think Phillc hit the nail on the head with his comments.

Whenever you have an application running in a production environment that people count on working, you have to have a mechanism for 'freezing' the environment. Updating rails could cause your application to stop working correctly.

It could be something minor or something that stops your users from getting their work done.

Just google 'rails gem update breaks my app' to see some tails of woe.

Igor Minar has a good blog entry on why you should freeze both gems and Rails as well as discussing how you can now set specific gem version dependencies in Rails.

You can freeze Rails, you can freeze gems, you can set dependency on specific gem version in your environment.rb file.

The reason you would do this is to ensure that your app does not break when an updated version of a gem or of Rails is released. Freezing lets you test an update on a separate machine, make sure it passes all of your automated test suites, lets your users put the updated app through its paces, and then (after a good backup) you apply the update to the gem or to Rails.




回答3:


Freezing is great - as others have said it reduces your dependency on your external environment. It's particularly important if you're on shared hosting, or otherwise don't fully control where you deploy.

However, it can be problematic for programs like rake and capistrano that don't run within your Rails environment. They have their own gem loading path, which you can affect, but you need to be aware of it. Also, a gem with native extensions (libxml, hpricot, ...) can't be frozen, because the OS-specific bits still need to live in the external OS.

Also, probably not an issue right now but something to be aware of - Rails 3 will be moving to a new method of managing plugins, gems, and the vendor directory in general. It's all kind of a mess at the moment.




回答4:


Here's a tutorial that goes into freezing a rails app.



来源:https://stackoverflow.com/questions/799416/whats-the-point-of-freezing-your-rails-version-gems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!