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.
Related
i'm new user here. and this is my first question regarding Ruby on Rails. so, i wanted to ask what is the correct program version of Ruby on Rails, i have seen only 2.1 and 2.2.
i was looking for 5.0 to install and use it for first time. i chose RoR (nickname for Ruby on Rails) to create a website that can have many useful features like a site would do. but i'm at loss because i have no idea where i could find a RoR 5.0 or should i just install a older package of RoR to update to 5.0?
also, i have additional questions.
1: is RoR a program that can help you make website or blog, forum? or it's just a one in all package?
2: can you actually put together a section inside a site for news information/updates?
3: where do you find or make a code for mailing list which users can have a mail updates sent to their email?
these are my questions, you see i'm quite fond of a site that is run on RoR. so i'd like to try my hand on creating a site of my own, particularly one with a forum. like any kind of development, it's fun to learn. will you answer my questions and help me learn the program of Ruby on Rails?
Ruby is a programming language which has it's own version number. Rails is a library written in Ruby which has it's own version number as well.
The version of Ruby is not the same as the version of Rails. Rails 5.x requires Ruby version 2.2.2 or higher.
You can view the versions of each by using
$ ruby --version
$ rails --version
You can use the latest stable version of Ruby. – get it from here: https://www.ruby-lang.org/en/downloads/ (The current latest stable is 2.3.1)
To get the latest version of Rails, use the gem install command. (The current latest stable version is 5.0.0.1)
$ gem install rails
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'm beginning to learn Ruby on Rails, I installed the latest ubuntu release on a VMWare machine and started the ruby on rails setup process using the mini-guide in this online book (which was recommended in stack overflow more than once). I'm wondering:
As part of my environment setup process I installed RubyGems and used it to install Rails (which is, if I understand correctly - a gem itself) the first time.
Now, when creating a new project using rails new project_name I later on edit the Gemfile and specify "rails '{version}'", which, from what I understand, installs the Rails gem in the context of the project (after using bundle install)...
Why would I need both of them? I'm kind of confused and would be more than happy if someone could shed some light over this...
Yes, this is a bit confusing.
When you run rails new project_name, you are using whatever rails executable is available in your shell to start a new rails project. To see what version this is, run rails —version. This does not "install the rails gem" — it just generates the tree of files to get you started on a new rails project.
You'll then specify in your Gemfile which version of rails your project will use.
So, be sure to have the latest version of rails available to your shell when you generate your new project, so that you get the newest version of the files it generates.
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.
I'm new to Rails development, and I'm trying to figure out how to use an older version of Rails with Apatana's RadRails IDE. I'm trying to help out a friend who has a site built on older version than the one that automatically gets downloaded by RadRails, and I'm pretty sure the two versions wouldn't be compatible (the site is using some pre 2.0 version, not sure of the exact number offhand).
Is there a way to tell RadRails to get and use a specific version of Rails? Or is there something I can do at the command line to change the installed version of Rails? I'm only vaguely familiar with the "gem" package system, but I'm assuming it would involve that.
Any help would be much appreciated!
Use the Rake task rails:freeze:gems in your rails project and give it the version you want to use. For example:
rake rails:freeze:gems VERSION=2.1.0
That will put the right version of Rails into vendor/rails, which is loaded by default if it exists.
If you don't want to freeze the gem into your project (using rake rails:freeze:gems), you can install the rails gem of the version you want to use:
gem install rails -v 2.0.2
and then specify the rails gem to use in your config/environment.rb:
RAILS_GEM_VERSION = '2.0.2'