Where are Ruby gems located on a server? - ruby-on-rails

My understanding is that the gemfile in a Rails app only provides references to the actual code of these gems on your local computer. So when you're running your app locally, it's pulling the gem code from your local computer. What happens when you deploy though? The server runs your rails code, but does it also hold all the references in your gem file and automatically download them as well?

Yep. If you deploy on Heroku, you can see bundler doing its work and pulling down the gems.

As per the Bundler docs, you can use bundle show --paths to see exactly where your gems are being loaded from.
Additionally, if you aren't using bundler, you can use the command gem environment to see gem paths on the system.
See this existing answer for more info: How can I find where gem files are installed?

Related

Bundler and Heroku with offline gems

I'm running a Rails 3.2 app that depends on an offline gem, chilkat. (http://www.chilkatsoft.com/ruby.asp).
I've gotten this to work on my development environment by doing the following:
Unpacking the gem into my vendor/gems folder
Adding this line to my Gemfile
gem 'chilkat', '9.4.1', path: 'vendor/gems/chilkat-9.4.1-universal-darwin-12', require: false
(These steps were taken from How to use Bundler with offline .gem file?)
BUT when I push the code to Heroku, the app crashes with the error:
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:317:in `rescue in depend_on': No such file to load -- chilkat (LoadError)
Do you know what I need to do to get the gem installed properly on Heroku? Thanks!
Ok I figured out the issue. The Chilkat gem I'm using has OS-specific versions, and the version I unbundled in vendor/gems is for OSx won't work on Heroku/AWS. So even if the path would have worked correctly in Heroku, the gem itself would not.
The problem I face now is because the Chilkat gem is OS-specific, Bundler will generate a Gemfile.lock file specific to the OS on which bundle install was called (OSx in my case). That OSx-specific Gemfile.lock is incompatible with AWS's machines, so Heroku complains that I can't push the code since the Gemfile.lock is inconsistent with what is expected.
This appears to be a known issue with Bundler (How to add Mac-specific gems to bundle on Mac but not on Linux?). I could just avoid committing Gemfile.lock, but we rely on the version dependency management that Gemfile.lock provides. And I don't want to get all the developers on my team to switch to developing on Linux/Unix. Anyway that's a separate issue so I'm closing this for now. Thanks to the people who commented!

Production not finding certain gem methods

I've added added the gem simple-navigation 3.9.0 to my gemfile in rails 3.2.11 and it runs fine in development. However, when I deploy to my production server and try to open a page with the method I get the following error:
undefined method `render_navigation'
I don't believe it's specific to that one gem though, as I had the same problem earlier when I used the uuid gem.
Using $LOADED_FEATURES I find "simple_navigation", so it seems to be loaded.
Info about the production server
nginx 1.2.6
Unicorn 4.5.0
Rubygems 1.8.23
Ubuntu 12.04 LTS
rbenv 0.4.0-9-g045f6c1
EDIT
Other gems work, the server runs fine, except for the above problem.
Make sure your gem is not declared inside the development group in the Gemfile
The gems in the development group are not be loaded in production.
group :development do
gem "simple-navigation"
end
Also, if you have a <APP_HOME>/.bundle/config file, ensure that it doesn't have the BUNDLE_WITHOUT option.
Gemfile
group :ui do
gem "simple-navigation"
end
.bundle/config
---
BUNDLE_WITHOUT: ui
In the above example, the gem group ui will not be loaded.
Having said that I had very-very limited exposure to Rails, I saw similar behavior when Gemfile.lock wasn't committed into repository. As result when project was pushed to production envinronment there was some screw ups with dependency resolution.
Have you try RAILS_ENV=production bundle install ?
While technically not an answer, I decided to switch over to Linode as my host. This involved a complete re-install of my server setup and it's working now. I did the exact same steps installing the server this time as last, so I'm still not sure what was wrong, or if it would have been easily fixable. Since I no longer have the old server available it would be impossible to confirm any solutions proposed from now on.
I'm going to mark this answer as the solution unless there are any objections within the next 48 hours.

How to move ruby gems from one server to another

I have a RoR server that I am decommissioning and need to move the existing Rails apps to a new server. The Rails apps are running Rails 2.3.5 and RubyGems 2.3.5.
The problem I am having is that some of the Gems do not seem to be available anymore - one example is thoughtbot-paperclip --version=2.3.1
I need to install these gems in order for the apps to work on the new server.
Would these gems have been removed from the remote repos? And if so how can I transfer them to the new server? I have tried just copying the entire gems folder from one server to the other but this does not seem to work.
Most of the old gems got renamed, as they usually were in a github_username-gem_name format. But after GitHub stopped hosting gems and gemcutter.org came, they got renamed to only the gem_name, such as thoughtbot-paperclip to just paperclip.
You might get away with just specifying the version number in a Gemfile, such as
gem 'paperclip', '2.3.1'
Looks like the gem has been renamed to simply paperclip. Check the repository.

When to Add to Gemfile and when to just install via CLI

I'm just getting started with rails and I'm a little confused reading through different documentation as to when you should add the gem to your gemfile and when you should just "gem install XXX"
For example, when installing rspec and guard-rspec. I see that some folks will:
gem install rb-fsevent
and some people put it in their gemfile and bundle.
Which is the right way and how do you know which to choose? Thanks!
The Gemfile records and manages all the dependencies for the application. When you list gems in the Gemfile, bundler sorts out any version conflicts and makes sure that the correct version of the gems are used with your application.
When you set up the application in a new environment (such as when your colleagues pull your changes from version control or when you deploy to a production web server), Bundler can use the gem file to ensure that the environment is set-up exactly as you had it in development.
So, anything on which your application depends (any code you call from your application for example), needs to be in the Gemfile. This includes libraries that you use for testing (although they can be excluded from the production environment).
Gems that are not dependancies of your application don't need to go in the Gemfile. An example would be guard which is more of a development tool than an application dependancy. You can install those with the gem command.
Typically though, most things you're going to want to install probably need to be in the Gemfile.
It doesn't matter if you install it with the gem command however. You can still put it in your Gemfile afterwards and Bundler will work out what to do.
All gems you will use in your application you should put into Gemfile.
All gems that will be just serving your application you'd better keep out of Gemfile.
For example. You need paperclip and mysql2 gems to store pictures and data, so put them into Gemfile. And you need magic_encoding gem to do some helpful stuff. But as far you are creating it straight from console, you don't need it in your application. Keep it separate from your app.
You use test frameworks when writing code, so put them into your Gemfile.
You use passenger gem to deploy your apps, but you never need to use it right in your code - don't put it into Gemfile.

Can't find data_warehouse ruby gem

I am working on a project and i was trying make it up and running in my local machine. But unfortunately the app is using a gem data_warehouse( found gem 'data_warehouse', '= 1.5.2' in environment.rb), I tried to look for this gem but can't find this gem, I was unable to run the application because of this. I never used data warehousing in ruby on rails either. I am slightly aware of the concept data warehousing. If any one aware of this gem please post the url for this gem or an alternate solution for avoiding this problem.
Neither can I. Now, assuming that you have a production machine where this gem is found:
You can see the installed gems with:
gem list
Go to production machine and run
gem env
There, you should see something like
REMOTE SOURCES:
http://gems.rubyforge.org/
http://gems.github.com/
After running the same command on your local computer, you can add the missing remote sources with:
sudo gem sources -a "http://missing_remote_sources"
and then try to install your gem.
If this doesn't work, you could also try a monkey-patch. Run
rake gems:unpack
on your production server. After this, you will be able to find your gem in the /vendor/gems folder. Copy the folder into your local vendor folder and it should work.
Btw, as it could just be a typo: have you tried commenting the line in the config file?

Resources