Rails: using rails 5 and generating rails 4 template app - ruby-on-rails

My machine is using Rails 5. Because some business, I must create new rails 4 application. I have using following syntax for generating rails 4 app:
rails _4.2.3_ new demoapp
Nevertheless, new application structure is built for rails 5. My question is: how can I use rails 5 for generating rails 4 structure app.
Thanks

First of all try to find out if you have that version installed. In this case, run this command:
gem list rails
You should see the list of gems you have installed on your computer that contains the word 'rails' in the name and also you will see the version (or versions) of that gems that you have installed.
Find where does it says rails and there you will find all the versions you have installed, in my case it is: rails (5.2.0, 5.1.6, 5.1.4, 5.1.3, 5.1.2, 5.1.1, 5.0.6, 5.0.3, 5.0.1, 5.0.0.1, 4.2.0)
So I can run the command rails _4.2.0_ new myapp and it will create a new app using rails 4.2.0.
If you don't have that version installed just run the command gem install rails -v 4.2.3
And there you have it.
References:
Specifying rails version to use when creating a new application
How to install a specific version of a ruby gem?

Related

Use an older version of Rails with Rails 6 installed

Thank you this community for getting me started on the right path. Specifying rails version to use when creating a new application gets me close, but the differing ruby version is what is throwing me off. I'm running into an error after running rails new that I'm not sure where to begin to resolve it. I gather from the error that my command is missing a parameter, but I can't determine what it is.
Any advice?
I would like to create a rails 5.2.6 project and I'm finding consistent responses elsewhere indicating that my approach to getting a rails project created with a specific version is to:
install the rails gem with gem install rails -v 5.2.6
create a new rails project, specifying the rails version with rails _5.2.6 new appName
I think I'm on to it. Did a specific google search for compatibility of Ruby 3 with Rails 5 and appears this is the likely problem.
I've now run 'rvm install 2.7.4' then 'rvm use 2.7.4' but still seems to be using ruby 3 in the command. The new error:
user#ubuntudev:~/railsprojects$ rails _5.2.6_ new rpapitest
/home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem railties (= 5.2.6) with executable rails (Gem::GemNotFoundException)
from /home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
from /home/user/.rbenv/versions/3.0.0/bin/rails:23:in `<main>'
Try with rbenv global 2.7.4 if you have rbenv installed

Changing default rails in ubuntu

I am working on Ubuntu . Initially I have 3 version of rails installed 3.2.9 , 3.2.12 and 4.0.0 . Running rail -v was showing Rails 4.0.0 . I tried to uninstall Rails 4.0.0 using gem uninstall rails 4.0.0 . Now Running gem uninstall rails gives this output:
Select gem to uninstall:
1. rails-3.2.9
2. rails-3.2.12
Running rails -v now also gives Rails 4.0.0 .Any guesses how can i change default rail to 3.2.12.
Investigating more on Thaha kp comment, I found this:
rails _3.2.12_ new myapp # slightly different version positioning
that means, you can install as many rails versions you want in one ruby environment, and when you start a new app you just need to specify what version to use.
Now if you started your app in rails 3.2.10 and want to upgrade to rails 3.2.11 you just change the version in your Gemfile as Bharath Sankar suggested, after a running bundle your app will use 3.2.12 version.

can't create plugin with Rails 3.2?

i've a problem with rails in latest version.
I 've create a new app (rails new MyProject) but i don't have script/generate, only have script/rails and when i type
ruby ./script/rails generate plugin my_plugin
"Could not find generator plugin.".
Do you have any idea how generate plugin template?
it's possible to create plugin without this command?
PS: i'm using Rails 3.2.1 with ruby 1.8.7 [universal-darwin11.0]
The plugin generator has been removed with the release of Rails 3.2.0. See the changelog here. Now you can use the following command:
rails plugin new my_plugin
But be careful because you should run the command outside of the project. It creates a whole plugin structure with its own Gemfile. So, after created the plugin, you can use it in your Rails app adding it to the Gemfile with the path option. Something like:
gem 'my_plugin', path: '/path/to/my_plugin'
I just read that you're using Ruby 1.8.7. Please consider to upgrade to Ruby 1.9.3. Rails 3.2 is the last version of the framework that supports Ruby 1.8.7.

Ruby on Rails 3 Tutorial: Chapter 2 Section 2.2.1 A User Tour

I am new to Ruby on Rails and am working through this tutorial book. I am on Windows Vista and using Cygwin. Here are the versions of the software that I am running:
Ruby version 1.9.2 (i386-cygwin)
RubyGems version 1.8.10
Rack version 1.3
Rails version 3.1.0
JavaScript Runtime JScript
Active Record version 3.1.0
Action Pack version 3.1.0
Active Resource version 3.1.0
Action Mailer version 3.1.0
Active Support version 3.1.0
In the beginning of section 2.2, I was able to successfully run: ($ rails generate scaffold User name:string email:string) and ($ rake db:migrate). But when I went to run the ($ rails server) command and opened up the webpage in Chrome, I did not see the screen shown in Fig. 2.4. But instead saw this instead: "Encoding::InvalidByteSequenceError in Users#index" I saw the post about switching the rake version from 0.9.2 to 0.8.7 and I tried this, but it didn't work for me. Does anybody now of anything else that I can try? Thank you, Nick.
I've tried rails learning with Windows 7 + Cygwin and it was a real pain in the ass. I strongly recommend you to run linux on the virtual machine or make a dual-boot.
Since you are using ruby 1.9.2 you can try to add # coding: utf-8 at the beginning of Controller file

Create new Rails project with previous rails version

The latest version of rails installed on my mac is 3.0.0.beta
gem list returns
rails (3.0.0.beta, 2.3.5, 2.3.4, 2.3.2, 2.2.2, 1.2.6)
I want to create a new project using version 2.3.5
So I run: rails _2.3.5_ myProject
But it returns the following error
$ rails _2.3.5_ photosbackup
/Library/Ruby/Site/1.8/rubygems.rb:777:in `report_activate_error': RubyGem version error: railties(3.0.0.beta not = 2.3.5) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems.rb:211:in `activate'
from /Library/Ruby/Site/1.8/rubygems.rb:1056:in `gem'
from /usr/bin/rails:18
Any idea how I can create a new project using version 2.3.5?
Thanks
I think you can just uninstall the previous Rails versions.
Which can be problematic - I have a number of Rails 2.3.5 (and earlier) apps in production that require maintenance and won't be upgraded to the new version.
So what I recommend in this situation is having a look at RVM - it lets you install and manage multiple versions of Ruby, and provides isolation between sets of Gems. I now run a Ruby 1.9.1 with Rails 3 and friends in isolation from my default system settings which let me do my day to day work.
even i had the same problem but the following command worked for me
rails 2.3.5 new myProject

Resources