Updating Ruby 2.2.3 to Current - ruby-on-rails

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/.

Related

Controlling Ruby Version

Forgive me if there's a duplicate, but I'm honestly not sure what to search for. I'm working on a project with Ruby on Rails, and I get this message when doing anything related (ie: rake, rails, rspec, etc.):
Your Ruby version is 2.1.5, but your Gemfile specified 2.2.3
Now, I've installed RVM and I can fix this issue by issuing the command
bash --login
edit for clarity
running the above command does use Ruby 2.2.3 to execute the commands.
/edit
Then those given commands work. What I would like to do is to remove version 2.1.5 entirely -- leaving only 2.2.3. I've gone about this so many different ways, but Ruby is pretty foreign territory to me so I'm not sure what to do about this. I'm sure I have at least three installations of Ruby on my machine - possibly two duplicates of the two versions I know I have - and I would like only one version and to avoid needing to enter the bash --login command in order to run my project.
I'm running Ubuntu 15.10 and have at least some knowledge of how this works. If somebody could walk me through removing everything related to Ruby & Ruby on Rails, then installing only Ruby 2.2.3 and Rails 4.2.4, I would greatly appreciate that. Let me know if this isn't the proper exchange for this question. It didn't quite seem to fit into Ubuntu or Sysadmin.
What you need to do is not try to remove ruby 2.1.5.
You have RVM, so, use that to get the new version you want.
After this, you now have two options:
1) make the newly installed version the global default version on your machine,
or
2) create a gemset for your project, and specify the needed ruby version for the project.
Either of these will fix your problem.
You have to modify the Gemfile.
http://bundler.io/v1.3/gemfile_ruby.html

Is there a development environment 'checklist' I can run through before starting to code?

I am following Michael Hartl's Rails Tutorial, and have gone through setting up my Development Environment.
I want to quickly check I have everything in order i.e. RVM, Ruby, Rails, Git, etc. all installed in the right place and correctly configured.
If you were picking up a beginner's computer and wanted to understand their development environment and spot anything missing (before running into errors later on), is there a hygiene checklist you go through?
How can I do this?
Thank you!
Michael hartls tutorial explains well what you need, but for a short list:
Curl
is needed to get RVM and to test HTTP requests. You will need it to install some requirements also.
Git:
You need it during the tutorial, and to get some gems directly from github.
Any JS platform:
I've choosen NODEJS because it's the easiest one to install, but you can use any of your like: rubyracer, v8...
Ruby interpreter:
Then Install a ruby version. I've always install the last one as default and then install the ones needed in the project.
The gems:
If you are using Ruby > 2.0 install byebug if not install debugger. And rails, the last version as well. If you are following a tutorial install other version.
Any editor:
If you want to learn I recommend you VIM, as you will get used to develop and will learn a nice editor. Learning a nice command line editor is allways payed. So don't be afraid. You can learn sublime or gedit at any moment, but learning VIM is hardest, so start now.
Then databases.
Install whichever you want:
MySQL.
PostgreSQL
SQlite
Or mongo, just to practice.
that should be enough to start the tutorial.

how to upgrade rails application from ruby 1.9 to 2.0

I have my current application in Ruby 1.9.3 and I want to migrate it to ruby 2.0. I have googled it but couldn't find any resource that clearly describes the steps required to upgrade to 2.0. Can anyone give me the stepwise guide for migrating from ruby 1.9 to 2.0? thanks in advance.
This is a detailed instruction:
install new ruby version
run all tests
fix all errors
profit
You need to follow the following steps:
Install new Ruby Version
Run bundle install (you may need to update some gems and rails)
Run tests . (If you have coverage of all of you application. If not run the whole application manually and fix the errors. Most of the errors would be syntax and other small issues.)
Your application is migrated.

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.

Do I need to revert to an older version of Rails just to run a single legacy app (among other problems)?

I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0

Resources