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.
Related
Is there a way to generate a rails project with a 'minimum' Ruby version? Perhaps to exclude the version altogether?
Situation: I am working on an introductory rails project with a remote partner (paired programming). We have a small difference in ruby version (2.5.1 and 2.5.8).
Set-up:
$ rails _5.2.3_ new my_project_name -G --database=postgresql
We then update the gemfile to allow 'at least' version 2.5.1:
ruby '~> 2.5.1'
Each time we pass the project it requires that we edit the /.ruby-version file to 2.5.1 and 2.5.8 respectively.
This /.ruby-version change is what I am trying to solve more permanently.
I am new to programming!
There are ways you could force this to happen (go down the rabbit hole of .gitignoreing ruby version, etc)....but by far, the best way is to be developing on the same ruby version.
I finished Michael Hartl's tutorial and created an app using Ruby 1.92 and Rails 3.2. Now I want to make my own app but I want to use the new versions of Ruby and Rails.
If I install the new versions for my new app, can I still make changes to my old app without things getting messed up or do I have to keep installing/uninstalling different Ruby and Rails versions?
You should look at using a ruby environment manager. I use rbenv, you can also specify in your gemfile which version of ruby and rails should be used for a specific application.
https://github.com/sstephenson/rbenv
You should be fine. Just make sure the proper versions are specified in your Gemfile and you will be good to go.
After installing the new version, by default new version will be used. However, already existing app will still use the version of rails they already exist as.
Bundler takes care a lot of the hard work for you in your situation.
Other notes:
Keep in mind RVM allows you to install "Gemsets". Should you have the need to use specific versions for gems you can create sets of them for use when needed.
You can also specify the version of rails when you're creating your app via rails _3.x.x_ new FooBar and you can identify what versions of rails are installed on your system via gem list --local | grep rails
If you need to negotiate local and global ruby versions, consider using rbenv.
https://github.com/sstephenson/rbenv
RVM is another popular option for ruby environment management.
https://rvm.io/
Personally, I have been more successful with rbenv.
I am looking for a piece of software that will allow me to use Ruby on Rails 2.3.8 on top of MACOSX - basically, I teach at a college where students are not able to get terminal acccess to the rails built into OSX so I am looking for a piece of software like "Locomotive" that is an app that allows students to use rails without administrator access to the computer itself.
Any one have any ideas?
We will be using Rails 2.3.8
thanks.
I encourage you to teach 3.0, but each to their own. If your materials only cover 2.3.8 then it's missing out on a lot of goodies associated with 3.0 (such as Bundler). Anyway:
My primary fear with this is that you're going to have an un-upgradable version of Rubygems if you don't have system privileges. Some gems require a Rubygems version >= 1.3.5 or even better, 1.3.6. Latest is 1.3.7. Thankfully, there's a way around it.
You can do this by installing the rvm gem:
gem install rvm --install-dir ~/.gems
RVM is "Ruby Version Manager" and does what it says on the tin: manages different versions of Ruby on your system. It'd be helpful in your case because it works without modifying the system Ruby.
This will install the gem to the user's home directory rather than the default system path. Then you'll need to run the rvm-install command which, as of this writing is:
~/.gems/rvm-1.0.14/bin/rvm-install
Your version of RVM may be different. To install a new version of Ruby which people can (ab)use run:
rvm install ruby-1.9.2-p0
1.9.2 is the latest stable version of Ruby and I highly encourage you use it rather than the older 1.8.7.
This should come with the latest Rubygems and, for bonus points, won't muddle about with the existing ruby installation on the machine (which is probably impossible if you don't have admin rights).
From this point, you'll be able to use
rvm use ruby-1.9.2-p0
to "switch" to that specific ruby. From there, you'll be able to do run gem install rails -v 2.3.8 which will install Rails somewhere in ~/.rvm. The location is not important. What is important however is that now you'll have a rails command that you can use and then you can go from there.
Good luck!
I'd like to use Rails 2.2.2 for one project and Rails 2.3.2 for another. Both are installed.
What is rails _2.2.2_ --version supposed to do? I've read that it makes 2.2.2 the working version -- that is, the version that will be used from that point on. But when I check rails --version, I get Rails 2.3.2. So, I also want to know what rails --version tells me; is it just the latest version of Rails that I have or is it the version that will be used for rakes?
I know about RVM. Is that the best way to use different versions of Rails on different projects?
Yes "rails --version" tells which is the latest version of rails. If you want to check different versions of rails installed in your machine you have to do "gem list" which gives the list of all the gems installed in your machine with their versions.For Ex:-
rack (1.0.0)
rails (2.3.4, 2.1.1)
rake (0.8.7)
Is that the best way to use different versions of Rails on different projects?
My point of view is that No it's not a good practise to use diiferent Rails version for the different projects. but sometime you used your old projects which is of an earlier version so you have no option but install that rails version. But while creating a new application you should used the latest stable rails version.
Just for record you can used different Rails version for different projects by mentioning Rails version in enviorment.rb For Ex:-
RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
I would try RVM gemsets for this, because it's likely that you will need to keep separate sets of dependencies for each project as well as separate versions of Rails itself.
RVM seems generally a much tidier approach - using separate environments instead of a single pool of gems means that you can easily create or destroy environments without breaking others, and it reduces the risk of making a mistake when you specify the versions of dependencies.
In the Python world people use virtualenv to create completely separate environments for each of their projects, and I think that this is a good idea to copy.
In the config/environment.rb file look for RAILS_GEM_VERSION and set the value to the required version.
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
OR
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
I would use Bundler: http://gembundler.com/
It's pretty easy to get used to, and has other benefits. It's by some of the Rails core members, and I believe will become the recommended solution soon after Rails 3.0.
To answer your original question, the underscore in your version number are used to specify a version when you create a new rails app. For example if you were to create a new rails app, rails would use the latest version installed in your system by default, but what if you wanted to use an older version installed on your system?
Here is the command...
rails 2.3.4 killerapp
You will need to have rails gem 2.3.4 installed on your system!
For that you can use rvm and gemsets to group your ruby/gems in convenient packages.
I hope this helps
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