Home > Enterprise >  Ruby on Rails "bin/rails routes" and "bin/rails server" not working
Ruby on Rails "bin/rails routes" and "bin/rails server" not working

Time:10-06

Recently started learning Ruby on Rails to build up a web API, code with VS code, following the youtube video: enter image description here

I have tried rake route but the result is not what I expected as in the video.

After that, I tried to start the server first with bin/rails server, and I keep getting the error:

/Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/object/duplicable.rb:85: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
=> Booting WEBrick
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
/Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
Traceback (most recent call last):
        9377: from bin/rails:3:in `<main>'
        9376: from bin/rails:3:in `load'
        9375: from /Users/jolin/Desktop/RoR/liborapi/bin/spring:15:in `<top (required)>'
        9374: from /Users/jolin/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        9373: from /Users/jolin/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'
        9372: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/spring-4.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
        9371: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/spring-4.1.0/lib/spring/binstub.rb:11:in `load'
        9370: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/spring-4.1.0/bin/spring:49:in `<top (required)>'
         ... 9365 levels...
           4: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
           3: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
           2: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
           1: from /Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>'
/Users/jolin/.rvm/gems/ruby-2.7.0/gems/activesupport-4.2.2/lib/active_support/core_ext/numeric/conversions.rb:131:in `block (2 levels) in <class:Numeric>': stack level too deep (SystemStackError)

I previous got undefined method <class:BigDecimal> error, but after add gem 'bigdecimal', '1.4.2' to Gemfile, it resolved, but I couldn't find a way to solve this issue.

I have so struggled even in the very first step, I have tried to upgrade/downgrade my Ruby and Rails in a different versions...

My current versions:
Ruby: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
Rails: Rails 4.2.2
(But with rails -v, I always got Deprecation warning: Expected string default value for '--rc'; got false (boolean).
This will be rejected in the future unless you explicitly pass the options check_default_type: false or call allow_incompatible_default_type! in your code You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.)
rvm: rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io] gem: 3.1.2

Update After trying upgrade ruby, downgrade ruby, downgrade rails I am now keeping getting error as below while I run bin/rails server:

Traceback (most recent call last):
        4: from bin/rails:3:in `<main>'
        3: from bin/rails:3:in `load'
        2: from /Users/jolin/Desktop/RoR/liborapi/bin/spring:10:in `<top (required)>'
        1: from /Users/jolin/Desktop/RoR/liborapi/bin/spring:10:in `read'
/Users/jolin/Desktop/RoR/liborapi/bin/spring:10:in `read': No such file or directory @ rb_sysopen - /Users/jolin/Desktop/RoR/liborapi/Gemfile.lock (Errno::ENOENT)

CodePudding user response:

I would recommend running it in Ruby 2.5.3 as in the screen shot. I don't think Rails 4.2 is tested or supported in ruby 2.7. You could also try installing the later version of ruby 2.7.6.

Current version of rails is 7.0.x, and Ruby 3.1.x.

Segmentation fault is usually a result of Ruby installation, you can try installing ruby 2.7.6 and try again.

CodePudding user response:

The rails routes command was introduced with Ruby on Rails 5.0. In versions prior 5.0 it was called rake routes.

This means because of the old version of Rails you are using you can simply call rake routes and get the same response.

But it is worth noting that the youtube video you are following is about Ruby on Rails 6.0. But you are using Ruby on Rails 4.2.2. Your local environment is 2 major versions and more than 4 years behind. You will very likely face more compatibility issues when you continue working with such an ancient and unmaintained version of Ruby on Rails.

I suggest that you upgrade your local environment to at least Ruby 2.7 and Ruby on Rails 6.2 or even better Ruby 3.1 and Ruby on Rails 7.0. There is no benefit in learning Rails is outdated and unmaintained versions.

  • Related