简体   繁体   中英

In Ruby on Rails, what's the difference between installing something as a gem or as a plugin?

On http://github.com/collectiveidea/delayed_job

it says:

To install as a gem, add the following to config/environment.rb:
config.gem 'delayed_job'
Run rake gems:install

versus

To install as a plugin:
script/plugin install git://github.com/collectiveidea/delayed_job.git

What is the difference between installing it as a gem or as a plugin?

Also, the first method just install gem 2.0.3 which might be the tobi's version? ( rake gems:install installs the version by gem list -r delayed_job ) Is it http://github.com/tobi/delayed_job ? The "plugin" method specifically says it is the collectiveidea version? Doesn't it matter which one you install?

Both the Gem and the vendored plugin refers to the collectiveidea's fork. In fact, collectiveidea is the current maintainer for the delayed_job Gem on RubyGems.

That said, generally speaking installing a plugins as a Gem has many advantages.

  • You can install it once and use it in many different projects
  • You can take advantage of dependency resolution
  • You can upgrade just changing version number
  • You don't need to store the entire plugin code in your SCM

So, why you can install a plugin "as a plugin"? There are many different answers.

At the very beginning, Rails plugins came as simple libraries. Time passes and developers started to notice the advantage of packaging plugins as Gem.

Also, before Rails 3, some plugin features were only reserved to plugins and not to Gems. For instance, before Rails 3, plugins could bundle rake tasks while there wasn't a way to inject new rake tasks or new routes into the main application.

In the last two years, the most part of Rails plugins offers the ability to be installed as a plugin or as a Gem. With Rails 3 and the arrival of Bundler, I'm sure plugins are going to be deprecated in favor of Gems.

That are 2 different repositorys, maybe you shoult try

config.gem 'delayed_job', :source => http://github.com/collectiveidea/delayed_job.git

Look at: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies

Btw. maybe you want to look at a maybe better solution: resque - see http://ruby-toolbox.com/categories/queueing.html for a comparison of used queing gems

当您安装gem时,它将适用于所有应用程序,以防您使用插件 - 仅适用于已安装的应用程序。

The basic difference is a gem is something that gets installed on the system running your Rails application, whereas a plugin is installed along with your application, plugin does not get installed on the system level.

suppose you are using rvm and let us take this example.

we have two applications app1 and app2

both are running on a common rvm gemset named gemset1

when you add a gem in the gemfile of app1 and run bundle install and then being in the same rvm gemset which is gemset1 , if you run the second app app2 the gem will be available in the second application as well

Whereas with the plugin it will not be the case because plugins get installed on application level and not at the system level

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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