rails not starting with the right version - ruby-on-rails

This must be a simple question, but I could not find the answer by browsing this forum.
When I check rails version, it shows version 3.2.8
user#domain.com [~/rails_apps]# rails -v
Rails 3.2.8
user#domain.com [~/rails_apps]#
But when I start the server, it runs version 2.3.11
user#domain.com [~/rails_apps/myapp]# script/server -p12011
=> Booting Mongrel
=> Rails 2.3.11 application starting on http://0.0.0.0:12011
/home3/user/rails_apps/myapp/config/environment.rb:45: warning: already initialized constant RAILS_ENV
NOTE: SourceIndex.new(hash) is deprecated; From /usr/lib64/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:100:in `new'.
=> Call with -d to detach
=> Ctrl-C to shutdown server
What am I doing wrong?

If you application is a 2.x rails application, you need to complete some changes before upgrade to 3.x
You may have a look to railscast http://railscasts.com/?tag_id=27
On the other hand, you may want to upgrade your ruby to 1.9 using rvm
rails 3.x work better with ruby 1.9

Try following in your environment.rb
RAILS_GEM_VERSION = '3.2.8' unless defined? RAILS_GEM_VERSION

Check your Gemfile and make sure it is pointing to rails 3.2.8
Then run bundle or bundle update

I wonder if this is an old app, built originally upon rails 2.3.1 and periodically upgraded insitu. Instead of script/server, try rails server
And make sure your Gemfile contains reference to rails 3.2.8

Related

I can't run my Rails web server

I have installed ruby193 and I've installed rails via the command prompt. However, whenever I try the command:
ruby script/server
I get this error:
ruby: No such file or directory -- script/server (LoadError)
I checked my script folder and all it has is a file called rails.
I'm very new to Ruby on Rails and I'm not entirely sure if I've installed everything correctly. Is there an easy way to check what I have installed?
To clarify on the existing answers, ruby script/server is no longer the proper way to start a server in Rails. In Rails 3, we use rails server, which can be shortened to rails s. See the Rails Guides for a more extensive rundown of the Rails 3 command line interface.
Try running rails server or rails s.
If you have Ruby & rails installed properly, then ruby -v would result in the version that you have installed and likewise rails -v would give the rails version installed.
To run a rails server try running rails server or rails s

Rails + rubygems + rvm disaster/confusion

I'm not sure exactly what I did but I messed up the Ruby/gem harmony trying to get an older 2.3.5 Rails app working on my system.
I'm currently using Ruby 1.9.2-p0 and rubygems 1.5.7. I've tried the newest one 1.8.2 but it just generates more warnings. I use these alongside of RVM.
I get "can't convert Symbol into Integer" when trying to boot a 2.3.x Rails app no matter what version of rubygems I run. I tried 1.5.7, 1.7.2, and 1.8.2.
$ script/server
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
path/.rvm/gems/ruby-1.9.2-p0/gems/rails-2.3.5/lib/rails/gem_dependency.rb:51:in `[]': can't convert Symbol into Integer (TypeError)
Any idea how I can get my system back in harmony?
As Dex and The Tin Man suggested in the comments, the solution was to run rails 2 on ruby 1.8.7 and rails 3 on ruby 1.9.2 using vrm. The warnings generated by rubygems 1.8.2 (now 1.8.3) are solved by running his suggest commands.

migrate RoR Project

have a existing Rails project, which was build on version 2.3.4.
On my local machine a have Rails version 3.0.3.
When a call rake db:migrate in the terminal, then the terminal replies following:
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.
A new created Project can be invoked by rake db:migrate
How can get running this project?
rake db:migrate loads up the rails environment, which loads up your gems, for which on this project rails 2.3.4 is used.
try using rvm to manage your projects, or you need to do gem install -v=2.3.4 rails to get this running. If that version is installed, rubygems will load it for you.

Ruby on Rails: switching from rails 2.3.8 to 3.0.3

In my env I require 3.0.3
but when I script/server
I get this: can't activate rails (= 2.3.8, runtime) for [], already activated rails-3.0.3
I don't want it to activate 2.3.8.. =\
Rails 3.x doesn't use script/server anymore - you should run your server with rails server or rails s. You can delete all the files from script, except for script\rails.
Plus, you no longer specify your Rails version in environment.rb (if that's what you mean by "env"). All gems and their versions are specified in your Gemfile.
Did you follow a guide like Upgrading to Rails 3? It's not enough to just change the Rails version in evironment.rb.
The command to run the server in Rails 3 is rails server. What happens if you run that?
Rails 3 uses
rails server
command instead of
ruby script/server
Check environment.rb to make sure that you're not specifying rails 2.3.8 explicitly. If you are then you need to make sure you've upgraded to bundler properly.
My suggestion is to generate an empty rails 3 project and look at how the generated files and make sure your app looks similar.

How do I upgrade from Rails 2.3.5 to Rails 2.3.8?

I've got a Rails 2.3.5 app that I want to upgrade to Rails 3. In the Rails 3 upgrade Railscast, they suggest upgrading to 2.3.8 before going to 3. I've tried Googling but the information I find is all about upgrading to Rails 3. I found this question, which seems to suggest doing gem update rails and rake rails:update, but wouldn't these commands upgrade to Rails 3, as it's the latest version? How do I upgrade to Rails 2.3.8? Thanks for reading.
There's not much difference between 2.3.5 and 2.3.8 (also, 2.3.10 is the latest version on the 2.3 branch - you should upgrade to that).
Install Rails 2.3.10:
gem install rails -v=2.3.10
Then edit config/environment.rb and change your Rails version to 2.3.10 near the top of the file. Start up webrick, deal with any deprecation warnings it throws at you while you click through your app, and you're pretty much done.
Citation from the Rails blog:
"We’ve released Ruby on Rails 2.3.9
(gem and git tag) to extend the 2.3.8
bridge a few steps closer to Rails 3
and Ruby 1.9. If your app runs on
Rails 2.3.9 without deprecation
warnings, you’re looking good for an
upgrade to Rails 3."
Edit:
Jeremy is on the money. Don't install 2.3.9, it has a serious security flaw. I've updated my answer to 2.3.10.
You can run rake rails:update - this updates the stock javascripts and config files. However, they probably won't need to be changed from 2.3.5 to 2.3.10.
$ gem install rails -v 2.3.8
Then change the RAILS_VERSION in your environment.rb file and run
$ rake rails:update

Resources