0

I recently created a new Rails project, and I believe I created a gemset for it before generating the app.

But when I encounter an error I get a message like this:

File /.rvm/gems/ruby-1.9.3-p194@project_1/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb

Even though I am in project_2. So in theory that should be ruby-1.9.3-p194@project_2 and not project_1.

What can be causing this and how can I fix it?

Thanks.

P.S. I am using RVM.

Edit 1:

I ran rvm gemset list and this is the output:

project_2$ rvm gemset list

gemsets for ruby-1.9.3-p194 (found in /Users/marcamillion/.rvm/gems/ruby-1.9.3-p194)
   project_1
=> project_2
   project_3

Edit 2:

I just ran gem install rails in my project_2 directory after I created the .rvmrc file for that project after verifying that it is indeed using the gemset for that project specifically. However, when I generate the error again, I am still seeing a reference to the gemset in project_1.

Edit 3:

The output for rvm current:

$ rvm current
ruby-1.9.3-p194@project_2

Edit 4:

Although, when I run rvm current in the same terminal window as my rails s I see:

$ rvm current
ruby-1.9.3-p194@project_1

So how do I set the gemset across all terminal windows for right now, and in the future?

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • You're getting that output from `rvm gemset list` and you are still getting the `project1` error above? – mraaroncruz Dec 13 '12 at 22:20
  • @pferdefleisch Yes...I am still getting that error, even after I did what jim-stewart suggested in the answer below. By the way, I even restarted my server, so not sure what's happening. – marcamillion Dec 13 '12 at 22:24
  • what happens after you `gem install rails` and try to generate it again? – mraaroncruz Dec 13 '12 at 22:26
  • Generate what? My entire app? This is an existing app, that I am not in a hurry to re-generate if I don't have to. Is that the only solution? – marcamillion Dec 13 '12 at 22:34
  • I just re-ran `gem install rails` and then `bundle update rails` after changing the rails version from `3.2.8` to `3.2.9` in my `Gemfile`. But I am still getting the error from the gemset in a diff project. – marcamillion Dec 13 '12 at 22:44
  • @SeanHill Just updated the question with that output. Basically it is showing the gemset for `project_2`. Do I need to do something special - aside from restart my rails server to get it to "make the switch"? – marcamillion Dec 13 '12 at 22:52
  • Okay, so did you restart the app after you have switched your gemset? Also, `rvm use` only applies to the current terminal session and future ones, but not to existing ones. You will have to run `rvm use` on every open session or just reenter the directory with the .rvmrc. – Sean Hill Dec 13 '12 at 22:54
  • @SeanHill Ok, I think I figured out the issue. I was using `rvm use` in a diff terminal window than my `rails s`. When I ran `rvm current` in the terminal window, I do see `ruby-1.9.3-p194@project_1`. How do I set the gemset across all terminal windows? Do I have to close all windows and restart them? – marcamillion Dec 13 '12 at 22:58
  • You can just run `rvm use ruby-1.9.3-p194@project_2` in all of them. Or, since you have created an `.rvmrc`, you can `cd ..` and `cd project_2`. It will get reevaluated once you enter the directory. – Sean Hill Dec 13 '12 at 23:01

1 Answers1

2

You need to tell RVM which gemset to use. Try this:

rvm gemset use project_2

If that works, then you may wish to create a .rvmrc file in project_2's root directory so that it automatically switches to that gemset when you enter the directory:

cd /path/to/project_2
rvm --rvmrc --create 1.9.3@project_2

That'll create a .rvmrc in /path/to/project_2. cd out of the directory and back in, and it'll prompt you asking if you trust the .rvmrc file. By default, it'll only ask you the first time.

Edit:

It is important to note that when creating a new .rvmrc, you need to cd out of the project directory in all open terminal sessions (including rails s and rails console). Otherwise the app will continue using the gemset from project_1.

marcamillion
  • 32,933
  • 55
  • 189
  • 380
Jim Stewart
  • 16,964
  • 5
  • 69
  • 89
  • That's the weird thing, I was already using the gemset for `project_2`. But I never had a `.rvmrc` in my `project_2` directory. Thanks! – marcamillion Dec 13 '12 at 22:21
  • Btw, even after I did this, I am still getting the error above. I also updated the question with what I see when I do `rvm gemset list`. – marcamillion Dec 13 '12 at 22:23