Rails isn't recognizing Rails gem - ruby-on-rails

I was working on a project just fine, logged off for the night and the next morning when I tried to start again I was getting this error:
Missing the Rails 2.3.12 gem. Please `gem install -v=2.3.12 rails`,
update your RAILS_GEM_VERSION setting in config/environment.rb
for the Rails version you do have installed, or comment out RAILS_GEM_VERSION
to use the latest version installed.
I did a gem list and it's definitely installed:
rails (3.1.0, 2.3.14, 2.3.12, 2.3.8)
I also made sure that 2.3.12 was the required Gem in the environment.rb:
RAILS_GEM_VERSION = '2.3.12' unless defined? RAILS_GEM_VERSION
Before I logged off I deployed my changes to demo, which was working fine, and when I checked it the next morning I was getting the same error message.
I'm still pretty new to RoR so I am not sure how to trouble shoot this.

I had this problem before and it was because I was defaulting to the system version of ruby. Run "ruby -v" in console and make sure you are using the version you want to. If you are not run this in the console:
$ rvm use "x"
Where "x" is the version of ruby you want to use.
Also, make sure your gemsets are in order. You can create and start using a new gemset by running this in the console ("xxx" = what you want to call your gemset):
$ rvm gemset create xxx
$ rvm gemset use xxx
After creating (and switching to) the gemset you can try reinstalling rails. Creating a new gemset means that there are no gems associated with whatever project you are working on anymore. So you will need to reinstall all your other gems too. Should be easy with a "bundle install"
Hope this helps.

Related

Rails not working on Mac in new terminal window

I have been using RVM (Rails 2.0.0) for a project in the terminal doing commands etc. and have noticed that when I opened a new terminal page the rails command didn't work it just shot back the error:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
But I had it installed and have even built half an app using it so far... what happened all of a sudden and how do I fix it to keep going with my project.
I was having the same problem on with the Rails tutorial. It looks like rvm is using the gemset defined in the Gemfile to override the default gemset. You should see this if you execute:
rvm gemset list_all
What I saw was this:
(default)
global
=> railstutorial_rails_4_0
So rails is fully installed in rvm's default gemset, but not in the new one ("railstutorial_rails_4_0" in this case). I solved this with the following commands:
bundle install --without production
bundle update
bundle install
This solution appears to have persisted across terminal sessions.
Okay so I got it to work by simple removing the code in the Gemfile that states the version of Ruby the app is to use and then it worked fine. Must of been some conflict with RVM installed on my machine and the Gemfile.

Update rails app to ruby 2.0.0 bundler error

I started a Heroku Rails app using Ruby 1.9.3 and Rails 4.0.1.
I decided soon after to update my ruby version to 2.0.0 as this apparently works better with Rails 4.0.1. So, I installed the ruby2.0 package using apt-get and other associated packages, then I set ruby 2.0.0 as the default using sudo ruby-switch --set ruby2.0, finally I updated the Gemfile in my app, changing the line ruby '1.9.3' to ruby '2.0.0' Now, when I run bundle install I am presented with this error, and I don't know why...
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
Following this heroku guide didn't seem to help... I set the path to what is shown there and it didn't seem change anything. Maybe I am being stupid and there is something in that path that I need to replace something with information specific to my machine? I feel like the part where I set vendor/bundle/ruby/2.0.0/bin should have some specific info, like changing "vendor" to something but I don't know what... I'm not totally familiar with this stuff yet, this is my first time using heroku and ruby.
EDIT: I forgot to mention (in case it is important) I am running Xubuntu 13.10.
I believe I have fixed the issue. I was somehow running the bundle command which was installed for ruby 1.9.3... so when it compared the gemfile definition with the version it was running on they mismatched. Re-rerunning sudo gem install bundler has sorted it out.

How to have RAILS 2.3.5 and 3.0.4beta installed at the same time

I'm working on two different rails installations for two different projects. They are on different versions of rails. Here's what I have installed:
gem list --local | grep rails
shows that I have this installed:
rails (3.0.0.beta4, 2.3.5)
When I run a command to do a deployment for the app that uses 2.3.5, I get the following error:
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your
RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do
have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
It's not finding the correct rails version, even though I have it installed. What are good short- and longer-term solutions for this problem?
I suggest you RVM. It allow you to have different ruby/gems versions on the same machine.
The long term solution is to look into rvm, especially the gemset feature makes it really easy to keep separate versions of gems and even ruby versions for different projects.
A short trem solution may be to add the the following line to your boot.rb file, somewhere before rails is required:
gem rails, "2.3.5"
This loads the right version of the gem, otherwise gem will think you want the latest version.
As others have noted, rvm is one way to solve this problem. The other is to use bundler, which involves some setup in your application and potentially requiring you to use 'bundle exec command' everywhere you want to run conflicting versions of a command (eg cucumber)

How do I switch to older versions of the ruby/rails environment?

I'm trying to keep along with the Tekpub Build your own blog on rails screencast. I'm still very much a ruby novice and the problem is that I have Rails 3 installed while Rob uses an older version (Of the top of my head: version 2.3.2).
I know how to get that version of rails with gem install rails --version=2.3.2 but when I type rails new the version of the application is rails 3. How do I make this particular app work with the older version? I know this has something to do with rvm but I have no idea how to do anything but the basic rvm use operation.
Try,
rvm use <ruby version>
rvm gemset create rails2.3.2
rvm <ruby version>#rails2.3.2
gem install rails --version=2.3.2
Finally the syntax to create a new rails app in older versions of rails was just:
rails <appanme>
For more information about gemsets:
RVM: Named Gem Sets
This will install Ruby 1.8.7 and then create a gemset that will contain only a specific set of gems:
rvm install 1.8.7
rvm --create use 1.8.7#old_rails
gem install rails --version=2.3.2
Whenever you want to use this after the first time just:
rvm use 1.8.7#old_rails
.rvmrc files are really useful for automatically managing different sets of Ruby versions and gems. If you create file called .rvmrc in the project directory and put this line in it:
rvm --create use 1.8.7#old_rails
Then every time you cd into that directory RVM will switch to Ruby 1.8.7 and the gemset "old_rails". Have a look at the docs for .rvmrc here: http://rvm.beginrescueend.com/workflow/rvmrc/
Of course you can change "1.8.7" for "1.8.6", "1.8.7-p249", "ree-1.8.7-2010.02" or any other Ruby version you like, I just assumed that you would want 1.8.7.
Have a look at RVM (Ruby Version Manager)

Missing the Rails gem. Please `gem install -v=2.3.4 rails`

I was trying to fix this error and I ended up with a new one.
I have installed ruby 1.8.6, but using Built-in JRuby 1.4.0 for my app.
Everything was working fine until I updated every gem(as specified by the answer I got from that link) and everything crashed: ever since I tried to start the app I received the following error message:
Missing the Rails 2.3.4 gem. Please
gem install -v=2.3.4 rails, update
your RAILS_GEM_VERSION setting in
config/environment.rb for the Rails
version you do have installed, or
comment out RAILS_GEM_VERSION to use
the latest version installed.
Then, I tried to uninstall the updates(to v2.3.8, most of them), so the last version is 2.3.4.
In my config/environment.rb file I have this:
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
so I guess everything is as I left it before the update.
The question is....why do I keep getting the error and I can't start the app?
Well, I got this working by changing the gem path for my Built-in Jruby 1.4.0 platform, pointing to the gems' directory of Ruby, instead of NetBeans(as it was before).
I hope it works well in the future.

Resources