简体   繁体   English

宝石还是插件,对Ruby on Rails项目有什么好处

[英]Gem or Plugin , what is good for a ruby on rails project

I am facing some problem with rails gem when deploying to a differet machine.It requires some extra work on installing gem.Which is most suitable for a rails project.Plugin or Gem. 我在将Rails gem部署到其他机器时遇到了一些问题,这需要在安装gem上做一些额外的工作,其中最适合Rails项目的是Plugin或Gem。 For Some gems there is no corresponding plugins found. 对于某些宝石,没有找到相应的插件。

I am searching for advantages of using plugin over gems and vice versa. 我正在寻找使用插件优于gem的优势,反之亦然。

You can unpack gems to your Rails application, which will make sure that they are deployed together with your application: 您可以将gem打包到您的Rails应用程序中,这将确保它们与您的应用程序一起部署:

rake gems:unpack:dependencies

Now you no longer have to install the gems on the server you deploy to. 现在,您不再需要在部署到的服务器上安装gem。 This already takes care of most of the deployment issues. 这已经解决了大多数部署问题。 Most others are solved by Bundler , which will be included with Rails 3. Bundler解决了大多数其他问题,该问题将包含在Rails 3中。

If you can, use gems over plugins. 如果可以,请在插件上使用gems。 Gems are generally easier to manage, because their versioning is superior to plugins. 宝石通常更易于管理,因为它们的版本优于插件。 For public Rails extensions, I see no reason to use plugins instead of gems, but some authors only offer one of the two. 对于公共的Rails扩展,我认为没有理由使用插件代替gems,但是有些作者只提供了两者之一。 In that case you have no choice. 在这种情况下,您别无选择。

I usually always use a plugin if it is available as it gets frozen into the project, meaning there are no issues when the project is deployed. 我通常总是使用一个插件(如果可用),因为它会冻结到项目中,这意味着在部署项目时不会有任何问题。 You can freeze gems into a project but if they require a native build it causes more hassle than it's worth from my experience. 您可以将宝石冻结到一个项目中,但是如果它们需要本机构建,则它会带来比根据我的经验值更多的麻烦。

My understanding is gems are easier to upgrade than plugins. 我的理解是,宝石比插件更容易升级。

You should also look into the rails 3 bundler which is used to handle these deployment issues. 您还应该研究用于处理这些部署问题的Rails 3捆绑器。

For me, plugins are preferred. 对我来说,首选插件。 I've run into many a situation where I'll have an improperly configured environment.rb and gems won't have versions assigned to them. 我遇到了许多情况,其中我的environment.rb配置不正确。rb和gem不会分配任何版本。 Then the server admin does a: 然后,服务器管理员执行以下操作:

sudo gem update

And now my rspec tests won't run because the update installed test-unit 1.2.2 and my specific setup needs 1.0.1 (or something). 现在,我的rspec测试将无法运行,因为该更新安装了测试单元1.2.2,而我的特定设置需要1.0.1(或其他功能)。

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

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