Is it possible to create a new rails application with a version of rails that we have not installed yet?

Finding the answer to the question above in Stackoverflow. I always came across a similar, but not equal question: is it possible to create a new rails application with an old version than the last one installed on my computer (one of the most popular messages of this type ? Specifying the rails version to use when creating a new application ). However , what I am interested in is to know whether it is possible to run a command like "rails __2.1.0__ new myapp" even if this particular version of rails is not already installed on my computer so that when it starts , it automatically installs this version of rails plus creates all the source files (in which the Gemfile contains all the compatible stones of this particular version).

As an example ... Right now, I'm following Michael Hartle's Rails Tutorial book, and we will be asked to use ruby ​​version 2.0.0, rails version 4.0.8 and include the following information in the Gemfile:

source 'https://rubygems.org' ruby '2.0.0' #ruby-gemset=railstutorial_rails_4_0 gem 'rails', '4.0.8' group :development do gem 'sqlite3', '1.3.8' end gem 'sass-rails', '4.0.1' gem 'uglifier', '2.1.1' gem 'coffee-rails', '4.0.1' gem 'jquery-rails', '3.0.4' gem 'turbolinks', '1.1.1' gem 'jbuilder', '1.0.2' group :doc do gem 'sdoc', '0.3.20', require: false end 

It happens that by default I am ruby-2.1.2 and rails 4.1.4 by default, so when I wanted to follow the Hartl book, I had to create a new rails application (which installs the Gemfile in accordance with rails 4.1.4), and after that I had cd in a new application , run $ gem install rails -version 4.0.8 to install the version, replace the default Gemfile that comes with 4.1.4 rails for the above code , then run the installation package and install the update .

This seems to work, but overall it's a rather tedious and annoying solution. Could this not be solved, as I wrote at the beginning, with "rails ____ 2.1.0 ____, new myapps" in which version 2.1.0 is installed (which I did not install)?

I'm sure there should be an easier way to get started with another rails version project, I just can't find it or try to solve it with the wrong commands. I am sure that the solution I implemented was not good enough, because whenever I try to create another rails application using the version that I presumably already installed (2.0.0), this is what I get from the terminal:

 Desktop$ rails _2.0.0_ new myapp /Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'railties' (= 2.0.0) - did find: [railties-4.1.4,railties-4.1.1] (Gem::LoadError) Checked in 'GEM_PATH=/Users/gaa/.rvm/gems/ruby-2.1.2:/Users/gaa/.rvm/gems/ ruby-2.1.2@global ', execute `gem env` for more information from /Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:322:in `to_spec' from /Users/gaa/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:53:in `gem' from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/rails:22:in `<main>' from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval' from /Users/gaa/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>' 

I am very grateful for the help.

+6
source share
2 answers

I think you are behind this:

 gem install rails -v 4.0.8 rails _4.0.8_ new myapp 

This will create a rails 4.0.8 application and create a default gemfile locked in 4.0.8. Less tiring.

You must install Rails to run the rails command. gem is an installer. Ruby must be installed in order to run gem . Ruby develops and fixes bugs; older projects may need older versions, etc. You probably need a ruby ​​version manager that gets its own installation (chruby, rbenv, rvm), which should be preceded by gem install ... You can block the ruby ​​version for the project, also in the Gemfile:

 source 'https://rubygems.org' ruby '2.1.2' 
+24
source

There are several ways to achieve this, but not using a standard generator.

When you start rails new myapp , what happens is that you execute the executable file (of the last or specified) of the installed library. This executable file downloads your project using the version template, obviously, without this generator you cannot download these files (since all the download information is in the library). Therefore, the best way is to install this version before using the method suggested by @JezC.

However, you do not need this generator to run the new rails application. You could just download the template from the Internet, make minor changes (these are just a few places you need to replace) and run bundle install to get all the necessary libraries. There are several ways to do this:

  • Cloning a GitHub Predefined Repository
  • Create all the templates on another computer and synchronize there
  • ... or even creating an application that conveys these patterns (which shouldn't be too complicated).

However, I can’t imagine a single scenario in which this can be useful, since when sharing a project, you can (and will) get the correct versions of Rails and the dependencies used in the project after bundle install 'ing.

0
source

Source: https://habr.com/ru/post/973518/


All Articles