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.
Related
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?
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.
What is the use of Gemfile in rails?
How to use Gemfile?
During your development in Rails, there will be times where you will want to provide some functionality which is required by you, but either you don't know how to do or you don't want to implement it on your own since a lot of work has been put into its development by talented developers.
These developments which you might need (user authentication, message system, asset handlers, geolocation, pagination system, linking to exterior services such as Amazon AWS, and last but not least Rails itself) are called Ruby Gems. These are ruby software packages, not necessarily relating to Rails, but since Rails is based on Ruby, 98% of the gems can be made availble to your Rails webapp code.
Lots of gems can be found in github, but its funner to search for gems via ruby-gems or ruby-toolbox
Your gemfile is a list of all gems that you want to include in the project.
It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems.
The gemfile has another purpose - you can group gems in :development, :test, :assets, :production, etc groups and Rails will know when to include the gems. For example:
group :development, :test do
gem "rspec-rails"
gem "factory_girl_rails"
gem "guard-rspec"
end
Note that on Rails 4, the assets group has been deprecated
These gems belong to development environment and the test environment since they are for testing the application. You don't need them available in the production environment (you could, but that will bloat the memory unnecessarily).
So - To use the gemfile, simply write the gem you wish to install such as
gem 'devise'
make sure to install bundler beforehand (in your console/cmd/ssh) with
$ gem install bundler
and then write in the console
bundle install
you will notice another gemfile appears! Gemfile.lock
This file, as you will see if you open it with a text reader, lists all your gems with their version and their dependencies. This will come useful when you need to know which versions of the gems you installed.
For more reading on the Gemfile - read on the bundler page
for information regarding picking a gem you could start with this
Good luck and have fun!
Ok, so whats this Gemfile.lock that got created?
Gemfile.lock, as the name suggests is a locking on all the versions of all the gems that got installed. So if Gemfile is what required to be installed, the lock file is what got installed and what version are actually required to get the app up and running.
If you don't have the gems in that specific version (as specified in Gemfile.lock) rails will complain and you will have to either install the missing gems (via bundle install) or fix any conflicts manually (I believe bundler will give you some clues on that)
Some things to know about Gemfile.lock
if you accidently delete it, it will get regenerated when you run bundle install. If you accidently delete Gemfile, you are out of luck.. You should use git :)
Heroku doesn't care about Gemfile.lock since it will reinstall all gems. So for Heroku, you must set the gem version you want, or Heroku will always install the latest version of gem, which may cause issues
Keep the Gemfile.lock in your project so you will always know what version of gems make your app work properly.
Gemfiles are configuration for Bundler, which is used to manage your application's Ruby dependencies. That website includes a lot of documentation, including the Gemfile manual page.
Explanation by analogy
You want to build a car. From scratch. You need to build: a chasis, engine, corroborator, radiator etc.
Gems allow you to utilise car parts which other people have made before
Everyone's who's ever built a car has needed the same things.
You needn't reinvent the wheel. Why make your own engine etc when you can get it straight off the shelf? What if you could get one of the best engines around, created by the most talented engineers in the world, without lifting a finger? Are you gonna spend a year trying to make your own?
So basically rather than make everything yourself, you write down a shopping list of all the parts you need:
Rolls Royce Engine
AutoLive seatbelts
Michellin tyres.
PIAA Night headlights
etc etc.
That my friend, is basically your gem file!
Your system can have lots of gems ... thus can have multiple versions of same gem.
A Gemfile specifies the list of gems with their versions that shall be used/loaded/(install if not present) whenever you run your rails application. or anything with bundle exec . .
Firstly, what is a gem?
According to Wikipedia:
RubyGems is a package manager for the Ruby programming language that
provides a standard format for distributing Ruby programs and
libraries
Gemfile
A Gemfile is a file we create which is used for describing gem
dependencies for Ruby programs
Now, in very very simple words:
Gem can be thought of as a library which you can use in your code.
Example: faker gem
Your code can use the functionality of faker gem to produce fake data.
Now you can list all the gems that your project requires in the gemfile.
When you do a bundle install, all the gems in your gemfile are installed for you.
I am developing a Rails app that uses a gem that I am also developing.
Every change that I make in the gem I have to: build, uninstall previously installed gem, install built gem, restart rails app.
You can imagine that it easily becomes a nightmare to make even litle changes in the gem.
I´ve tried to manually load all files that are configured to be loaded by the gem (at Gemspec) but it always seem to be some problem in the loading process, not finding libraries or not loading in the proper order.
Is there a way to set my environment to better develop my gem with my app?
You can just add a file reference to your local filesystem in your Gemfile, like
gem 'new_gem', :path => '~/RubyPlayground/DevGems/new_gem/'
That way you just need a new bundle install after modifying your new gem.
Update
Reading your description again you might not be using rails 32. My suggestion is of course based on bundler at least.
You could always symlink your gem code to lib/ and then include that in your autoreload paths (application.rb IIRC).
My question is very similar to How do I freeze gems into a Rails 3 application?, but I only want to freeze a single modified gem. The answers to that question seem to result in bundling all the application's gems.
In case it's relevant, I need to do this so the modified gem gets installed on Heroku.
I checked the bundle-install doc but it didn't seem to address this situation. I can't imagine it's that uncommon, though. Any guidance is appreciated.
Well, Bundler is going to freeze all of them, and the idea is that you want to freeze not only a single gem, but the collection of gems that produced a working copy of your app.
That being said, on your local dev machine, you can do bundle update [name of gem] and it will update just that one gem to the latest version within the restrictions specified in your Gemfile, which also updates your Gemfile.lock, which effectively updates just that one gem on Heroku when you next deploy.
If you're using bundler, which is the default for Rails 3, you can always fork the gem to your own git repository and add that definition to your Gemfile with whatever location it can be found at:
gem 'thegem', :git => 'git://github.com/cloned_to_me/thegem.git'
Another option is to use bundle package to save copies of the gems in vendor/cache. These can then be later installed using bundle install --local according to the documentation.
This is the closest thing to the Rails 2 "freeze" method, but has the added advantage of saving the gems before they are installed, not after, avoiding any platform-specific problems as was the case previously.
With thanks to those who answered the question with related approaches, I ended up going with the approach mentioned in this sister question. For the sake of clarity, this is what I did:
Repackage modified gem as its own gem. This takes a little finagling but is described well in the RubyGems Guides. Move said gem into your source directory (I used vendor/gems)
In the project's Gemfile, point to the location of the new gem:
gem "modified_gem", :path => "vendor/gems/modified_gem"
Add new gem to version control, make sure bundle install isn't messed up with funky settings (e.g. --local), and cross your fingers.
Someone also mentioned that it's possible to mix in changes to the gem instead of overriding source files. I don't know anything more about this technique except that it should be possible.