Convert a Gem to a Plugin in Ruby - ruby-on-rails

I currently have a gem installed on my development machine. Now that I want to use this gem on the production but I could not install it due to some issue with the server. Is there a way that I can convert this gem to a plugin so that I can transfer it to the server?
if no, is there a way to transfer this gem from my machine to the server?
BTW, I'm using an old version of Ruby on Rails (2.1)
Thanks.

Just copy the gem's single source code file into your project's lib directory. https://github.com/ambethia/smtp-tls/blob/master/lib/smtp-tls.rb

Well, if the plugin is compatible with Rails 2.1 you should be able to move the plugin to your /vendor directory, and it should work from there. As mentioned in the comments, the vendor directory is going to be removed and that style of plugins will be removed in Rails 4, but for Rails 2.1 that doesn't matter.
To get the files, go on rubygems.org and find the project homepage. You can probably find the source code for the plugin you're interested in (including a version that's compatible with Rails 2.x) on Github, then just clone it to your vendor directory.

Related

How to build a gem from rails source code?

I want to make a gem from rails source code and install the gem.
After clone the master repository of rails, I tried as follow.
$>gem build rails.gemspec
$>gem install rails-4.2.0.alpha.gem
It did not work. I also tried $>rake install which did not work either.
Looking forward your help!
There is a script in the root directory which builds from source and installs the gems. It's called install.rb. You can use it by running the following:
ruby install.rb 4.2.0.alpha
Note: At the time of writing this the arel gem needs to be built from source and installed separately before running the install script above. This is because the version constraints in rails are requiring a version of arel which has not yet been released onto rubygems.org.

Using gems vs copying folders for Bootstrap

I'm working on a Rails App with Bootstrap 3. What is the difference between adding bootstrapp-sass to my Gemfile and simply downloading Bootstrap and copying the css and javascript files into their respective folders of the Rails app?
I'd go with a gem because it simplifies the updating process. No manual copy pasting makes me a happier developer.
Also, bootstrap-sass is a port to SASS from the official Bootstrap, which uses LESS.
With gems you can always have the latest version if you keep your bundle up to date. If you copy the files, you will have to update manually when there are newer versions of the framework.

Rails: adding vendor/cache to SCM?

Page 239 of Agile Web Development with Rails instructs us to add the vendor/cache directory to git.
Is this actually recommended practice? I was under the impression that this directory was platform-specific. Will it cause problems to commit a cache dir under OSX and then deploy to prod under Linux?
This is where your app's gems are stored if you package them locally. So if you deploy from the SCM source and you want to use the exact gem packages that you are using locally, you'll need these files, which is why I suspect the book suggests this.
As far as the gem files go, it won't cause a problem if you develop on a Mac and deploy to a Linux server.
Short answer - yes.
Long answer - it's very handy to keep your gem dependencies with your application. Not just a Gemfile and Gemfile.lock but also the gems themselves.
There are numerous advantages - such as having all your gems available without having to connect to a gem server.

How to detect the rails version from an installed ruby gem

I want to modify an existing gem to compatible with new rails versions. My requirement is as follows
I have a gem which runs in both rails 2 and 3. But it has some stylesheet copy functions. So as you already know rails 2 has stylesheets in public/stylesheets folder, But in rails3 has assert pipe line.
So what I want to do it, I want to detect the rails version using by my gem installed rails application and according to the version I will handle the file copy.
My question is How an installed ruby gem reads the current rails applications version ?
Or is there any other way to do it ?
thanks
I took a look around in the latest stable source for Rails and found a version.rb file which indicated I could do this:
Rails::VERSION::STRING #=> "3.2.6"
If you look at Rails 2.3, you’ll find that the same thing works there.

what's the difference between gem and plugin?

I'm new to Rails and I'm confused about concept of gems & plugins. Can anyone explain them for me?
Plugins are just libraries loaded from a specific directory, gems are loaded via Bundler or RubyGems directly.
Where this really makes a differences is maintenance and management. What happens when you want the latest and greatest authlogic plugin, well you need to update the files in your directory. That doesn't sound so bad when it's one plugin, but what about something that constantly updates? There was/is an existing system for code packaging and distribution (RubyGems), which lends itself to managing such things.
Consider the authlogic example again, what happens if the new version requires some other dependency now? With RubyGems the gem file explicitly defines that relationship, the plugin system does not and such a definition would've been redundant.
With the advent of Bundler in rails 3.x it's become very easy to manage and distribute the gems that your project uses.
TL;DR: Plugins are basically gems without the packaging information.
Plugins are being used less and less so stick with gems. Gems and plugins can do exactly the same thing so that is why they are confusing. However the differences are how they are organized and most importantly how gems are managed such as bundler or config.gem. It is much easier to manage gems and their versions. Plugins must be installed in the vendor folder where as gems can also be installed in that folder if they need to be customized or they can be installed in a gem directory as long as rails understands where that directory is located. When rails started most people used plugins to added functionality but developers quickly realized that gems offered a better way to package and update libraries so most plugins have migrated to gems and fewer plugins are being built.
Gem and Plugin
gem is stored in lib files
A Gem is a packaged Ruby application using the packaging system defined by RubyGems.
plugins are stored in vendors/plugins
A Rails plugin is a packaged Ruby application that extends the core Rails framework.

Resources