How can I work with a different rails version? - ruby-on-rails

I have the "Agile Web Development with Rails fourth edition" and I have installed the 3.0.5 version of rails, but I'm using the 2.3.5 version, and much things in the book I tried I got fail, and I think is for the version. Am I in the true? How can I change my version?
thanks a lot!

The very first page of the book starts out with "this book is for Rails 3". There are many, many changes in Rails 3, so this book simply won't work with Rails 2. The previous edition is definitely what you want if you absolutely must use Rails 2.3.5.
Section 1.4 in Edition 4 is devoted to choosing a Rails version. In edition 3, this was covered in section 3.5.
Disclosure: I am one of the authors of this book.

You may need to update Ruby so have a look at RVM : http://beginrescueend.com/
Did you run bundle install to install the Rails version in the Gemfile?

Rails 3 uses Bundler (http://gembundler.com) by default. Use
bundle exec <command>
to run your commands using the correct version of rails.
examples:
bundle exec rake db:migrate
bundle exec rails server

Yes, the Rails version matters.
If you want to stick to Rails 2, you might need the 3rd edition of that book.
If the Ruby version you are using is 1.8.7 or 1.9.2, you can install Rails 3.
Are you using the Ruby environment bundled with the system? Or instant rails on Windows?
On Linux systems, you can install Ruby with the help of rvm, then install Rails using "gem install rails"
On Windows, you'd better get the latest version of Ruby from ruby-lang.org, then install Rails gem. That would be a lot of hard work.

Related

Updating Ruby 2.2.3 to Current

I received a ruby on rails application that was written three years ago
(Rails 4.2.1)
I need to update everything to current version of ruby, rails, rvm, bundler, rbenv, gems, etc...
Please help on process to achieving the update and the app to run not only locally but live.
To check what your ruby in now
$Ruby -v
Update it to ruby version 2.3.7
$rvm list known
$rvm install 2.3.7
$rvm use 2.3.7 --default
$gem install bundler
Let me know if does that help!
Hey dude upgrate from a very old to newest versions requires a lot of patient and skills. I found an article that might help you and also helped me before. I hope it can help you. Let me know if you have any more doubts
Upgrade ruby on rails project
Start a new Rails app with the latest Ruby, and use Test Driven Development to port the old app over, line by line.
Write a test that fails, copy a line out of the old app, pass the test, integrate & deploy, and repeat until all the features are installed - with tests.
TDD is where you write a test that fails, run it and make sure it fails for a correct, predictable reason, and only then add the production code that passes the test. Only integrate if all the tests pass. Learn more about TDD at its original web page: wiki.c2.com/?TestDrivenDevelopment . Learn to TDD in Rails by reading its flagship book, /Agile Web Development with Rails/.

Upgrading Rails with rbenv

I want to upgrade an application to the latest Rails version (4.2).
I'm using rbenv as a version manager.
Can I just install the rails 4.2 gem without affecting my other Rails applications?
thanks for your advice,
Anthony
rbenv is a tool for managing different ruby versions in your system. While it's possible to install different rails versions for a single ruby version installed using rbenv, installing rails is bundler's job.
Quoting from a really good answer by Nathan from here, where it's explained how would one install different rails versions for a single ruby version (go and upvote the answer if you find this helpful) :
So once you get rbenv installed, and you use it to install a specific
ruby version, you can install multiple versions of rails to for that
ruby.
STEP 1. Install whatever version(s) of rails you want per ruby version
% RBENV_VERSION=1.9.2-p290 rbenv exec gem install rails --version
3.0.11
By using the "RBENV_VERSION=1.9.2-p290" prefix in your command line,
you're specifying which ruby rbenv should be concerned with.
Then following that with the "rbenv exec" command, you can install
rails. Just use the version flag as in the example to specify which
version you want. Not sure if you can install multiple versions in one
shot, but I just run this command as many times as needed to install
each version I want.
Note: This will all be managed within your rbenv directory, so it's
perfectly safe and contained.
STEP 2. Build a new rails project by specifying the rails version you
want.
% RBENV_VERSION=1.9.2-p290 rbenv exec rails _3.0.11_ new my_project
STEP 3. Don't forget to go into that project and set the local rbenv
ruby version.
% cd my_project
% rbenv local 1.9.2-p290
And here is Michael's blog post explaining how one can manage different rails versions installed this way. You would basically modify the Gemfiles and specify the version you want, and then let bundler take care of installation. Here's the answer where he talks about this.
Also, I haven't tried rbenv-gemset but it looks promising at a glance. I would use it if I were you, at least to try it once. :)

Upgrading Rails

I have updated rails and have rails -v and it says 3.0.5. (which is good) when i open my old programs, will it still always use 3.0.4 as that is what was used?
And ..
when i create new one will it use 3.0.5
I have done this as i'm a newbie and having problems with tutorials from the rails by example book michael hartl and wondering if it is the version that is giving the problems.
Thanks for any help..
In Rails 3 Bundler was added to handle gem dependencies. Within each application a Gemfile exists that specifies the version of Rails to use. If you want to update an application change the version in your Gemfile and run bundle install.

Ruby on Rails: using rails 2.3.x and 3.0 on same machine

I just finished a project with rails 2.3.8. Client won't pay for the migration, so I want to keep it as is.
I want to start a new project, which is to build my own homepage. Want to use similar tools but want to go to rails 3.0.
Can these versions co-exist on the same machine? If yes, what do I need to do? Found few pages online, but not sure they are up-to-date (e.g. about rails 3 beta and rvm).
I'm using rvm and running 2.3.9 on ruby 1.8.7 and 3.0.1 on ruby 1.9.2 and it works quite well. I followed http://rvm.beginrescueend.com/rvm/install/ to get rvm installed and then switched to it with:
rvm use 1.9.2
Then you can install Rails 3 on that rvm, set up your new project and switch back to your system ruby and older rails when you need to with:
rvm use system
It's been a really great way of switching back/forth for me.
Make R3 the default for your system. Then freeze rake rails:freeze:edge RELEASE=2.3.8 applications if you need to develop with old versions
With rvm you can also use different gemsets with the same ruby installation:
http://rvm.io/gemsets/basics/

Managing many Ruby on Rails applications of different versions

I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here. I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily.
My question is: When I start contracting, developing and deploying projects in the real world, how am I going to manage all these different versions?
It looks to me like Rail's low tolerance for legacy code negates its ease of use philosophy! But I'm sure I'll grow to appreciate RoR.
As for Rails, What you can do is freezing your version, for example:
Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.2.2
Freeze and pack Rails with the project itself : rake rails:freeze:edge RELEASE=2.2.2
Now you will find Rails packed inside the vendor folder of your project, so you don't have to install Rails on the deploying machine.
And for Ruby, I like Ruby Version Manager(RVM), the easiest way to manage Ruby versions.
RubyGems is Ruby's package manager. You can install as many versions of gems (packages) as you want. You can install the latest by running sudo gem install rails (at the moment it will install 2.3.5). If you need 2.2.2, specify that with the -v or --version option: sudo gem install rails --version 2.2.2. Rails also installs a binary (yes, I know it's not really a binary file), rails, which generates a project. Because you have several versions of the gem, you need to control which binary gets called. When you install the rails gem, RubyGems puts a file in it's bin/ dir, which is a "link" to the real rails binary. That is the one you "call" when you say rails on the command line. However, all of the rubygems "link" binaries accept a parameter of it's own, which is what version you want to use. You would use the 2.2.2 rails binary like this:
rails _2.2.2_ my_project
I think the default is to use the most recent version, so if you want to use the most recent version, do this:
rails myproject
However, I see that you use 2.2.2 to get access to the scaffold method. I would strongly suggest you not to use that method, there's a reason for removing it. The scaffold method hides code, and makes customization hard. Instead, use the scaffold generator:
./script/generate scaffold --help
Good luck on your future rails adventures!
The latest version of Agile Web is written for 2.2.2 I believe. For this basic app they walk you through I'm very certain it should work with 2.3.x
The answer to the question for how you keep up is that you update your apps as needed and read the api and Changleogs to find out what has changed and fix the stuff that upgrades break. A great way to help with this is having a good test suite with good test coverage.

Resources