how update Rails ruby minor version - ruby-on-rails

If a Rails 6 Gemfile includes ruby "~> 3.0" and the current Ruby version in the project is 3.0.1, how does one upgrade Ruby to the highest current minor release (3.0.2 at this time) without modifying the Gemfile to specify an exact minor release (which would defeat the purpose of the "~> 3.0")?

The specifier ~> has a special meaning, best shown by example. ~> 3.0 is identical to >= 3.0 and < 3.1. So all minor patches are included. See https://bundler.io/gemfile.html.
No need to change your Gemfile just install the gems in the newly installed Ruby version.

Related

How to change from Ruby On Rails version 6.0.3.2 to Version 5?

I have installed Ruby On Rails version 6.0.3.2 but now I want to change it to Version 5. How can I do it?
Do I uninstall version 6 and install 5? What command should I use please?
You can have multiple versions of a gem installed:
gem install rails -v 5.2.4.4
And all modern rails versions have a way to select which specific one to use when creating a new app:
rails _5.2.4.4_ new application_name
If you want to downgrade an existing app - first search for a commit that upgraded it, if you're very lucky - a simple revert can do the job. But in more general case - you have to make your code compatible with older version (remove new feature usage etc), and fiddle with gem versions inside the Gemfile. Do a bundle update after edit - when a lower version is specified in requirements it will downgrade. Note that rails may be not the only gem requiring downgrade

specify a range in bundler ruby version

Is there a way to specify a range for ruby version?
ruby '~> 2.1.0'
Your Ruby version is 2.1.1, but your Gemfile specified ~> 2.1.0
ruby '>= 2.1.0'
Your Ruby version is 2.1.1, but your Gemfile specified >= 2.1.0
Obviously, ranges works for gems, but maybe it's not possible for ruby version. Or did I get my syntax wrong?
You can't set a range for the ruby version, see here
Syntax is like so:
ruby 'RUBY_VERSION', :engine => 'ENGINE', :engine_version => 'ENGINE_VERSION', :patchlevel => 'RUBY_PATCHLEVEL'
It is not possible in Bundler 1.x because it cannot be done maintaining backward compatibility with the format of Gemfile.lock.
As discussed there, this is arguably a bad idea unless the lockfile contains the ruby version. Adding the ruby version to the lockfile means Bundler 2 at the earliest.
(from an issue that has been filed requesting the addition of a range feature for Ruby versions)

How to upgrade to a release candidate?

I'm on Rails 4.0.4.
I would like to try out the latest relase candidate for 4.1.
How would I upgrade my Rails application to the latest RC?
If a gem's version number has a letter in the version then it is considered to be 'pre-release' and will be skipped by bundler unless you specify otherwise in your Gemfile.
If you want to use a pre-release version of a gem:
# Gemfile
gem "rspec-rails", ">= 6.0.0-rc1", "< 6.1"
This will install 6.0.0-rc1 and then update to anything in the 6.0.x releases (I think this includes future pre-releases) using the RubyGems pessimistic version constraints.
Source
You can run bundle update to update all your gems at once.
If you just want to update a particular gem (such as rails) you can run bundle update rails.

How to specify less than version in Gem Bundler

I'm trying to specify factory_girl_rails version less than 3.0 as I don't have ruby 1.9 installed and 3.0 isn't compatible with 1.8.x. I've tried a few ways round but it always tries to install 3.0.0 and fails on the ruby dependency.
According to this, Rails 3.0 should still be compatible with Ruby 1.8.7 (they aren't dropping Ruby 1.8 support until 4.0).
But, if you put this in your Gemfile, bundler should use the latest 2.3 version (the last minor version before 3.0) of Rails:
gem 'rails', '~>2.3'

Could not find a valid gem 'rails' (= 3.2.0) in any repository

I'm installing ruby on rails on my OS X 10.7 machine and trying to follow along with this book: Agile Web Development with Rails.
Anyway I have installed Ruby 1.9.3 and then ran gem install rails and it pulled down rails 3.1.3, now the book says when I run 'rails -v' I should get 3.2.0 or NEWER.
I checked out http://rubygems.org/gems/rails and it says the latest version is rails 3.2.0 RC2, how is it that the book specifies (in multiple places to it's not a typo) that it should be 3.2.0 or NEWER when 3.2.0 isn't even released?
Actually, if you want the latest unstable version, run this:
gem install rails --pre
It'll install the latest RC.
EDIT: as to why the included 3.2.0 when it is not out yet, I can't answer for them! Maybe you have a "beta" version of the book?
Looks like you're specifying an explicit dependency on a future version of Rails, probably something like gem 'rails', '3.2.0'. If you indeed want to use this version, you'll have to settle for one of the release candidates for now:
gem 'rails', '3.2.0.rc2'
Or borrow a time machine.

Resources