How to fix 'warning: constant ::Fixnum is deprecated' error - ruby-on-rails

When I'm trying to run my rails server from RubyMine IDE, I get the error:
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
ExitingTraceback
I'm currently running Ruby 2.5.5p157 with Rails 4.2.7.1. What should I do in order to run the web app? Thank you very much for your help!
Full log when attempting to run the website:
C:\Ruby25-x64\bin\ruby.exe "C:/Users/Sam/Desktop/Takai/Website/bin/rails" server -b 127.0.0.1 -p 3000 -e development -b 0.0.0.0
=> Booting WEBrick
=> Rails 4.2.7.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
ExitingTraceback
(most recent call last):
C:/Users/Sam/Desktop/Takai/Website/bin/rails: stack level too deep (SystemStackError)
Process finished with exit code 1

You are using an old version of Rails with a newer version of Ruby and Rails wants to use something (Fixnum) that doesn't exist anymore in the new version of Ruby.
You have two options:
Use a version of Ruby that is supported by your old version of Rails. According to this list Ruby 2.4 should work for you.
Update your Rails application to a newer version of Rails that supports Ruby 2.5. Rails 5.1 seems to be the first version of Rails which officially supports Ruby 2.5
The first option is probably much easier. But I still suggest updating your Rails version because your Rails version is unmaintained and will not get any updates or security anymore.

Related

Rails server getting error on the starting point

I have started a project to update, which was updated also a couple of months ago, but today it's not running on the development, I have deleted Gemfile.lock and reinstall the gems & update the bundler but showing still.
Here are below I have attached the full specification of this project.
// Environment
$ ruby -v
- ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin20]
$ rails -v
- Rails 5.2.6
$ bundle -v
- Bundler version 2.2.31
macOS v12.0.1
When running the rails server it's showing like this below
user#Users-MacBook-Pro max-domain % rails server
=> Booting Puma
=> Rails 5.2.6 application starting in development
=> Run `rails server -h` for more startup options
Exiting
/Users/user/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-5.2.6/lib/active_record/type/adapter_specific_registry.rb:9:in `add_modifier': wrong number of arguments (given 3, expected 2) (ArgumentError)
.........
....
I don't even find any clue where can I fix that!
Would you please help me out with that?
Thanks
If you want Ruby 3.0.1 you need to be on Rails 6.1 (and above). Max ruby version for Rails 5.2 is 2.7.0.
Here's a compatibility table.

Error on starting the ruby server, specifically SystemStackError

May be this is just a simple error but since I am Rails noobie any help to my problem will be greatly appreciated.
I have been facing the following error everytime I start the rails server.
I am using Ruby 2.6 and Rails 4.2
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.0/lib/active_support/core_ext/object/duplicable.rb:85: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-4.2.0/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
Traceback (most recent call last):
bin/rails: stack level too deep (SystemStackError)
Rails 4.2 does not support Ruby 2.6. You should be using Ruby 2.4 for Rails 4.2, as support for Ruby 2.4 was explicitly added in Rails 4.2.8.
If you wish to use Ruby 2.6 you'll want to use Rails 6. Upgrading from Rails 4.2 to 5 to 6 is a complex process so you'll most likely to have an easier time downgrading Ruby rather than upgrading Rails. Running Ruby 2.4 on Windows is an exercise left up to the reader, though.
You can read more about the compatibility between Ruby and Rails versions in this answer.

How to fix Rails's warning messages with Ruby 2.7.0

Did anyone resolve this issue with Ruby 2.7.0?
I used rbenv and installed Ruby v2.7.0 and then created a Rails project using Rails v6.0.2.1.
Currently, by running one of
rails s
rails s -u puma
rails s -u webrick
the server is up and the site is served but in the Console log I see two warning messages:
local:~/rcode/rb27$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.1 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
So, the warning messages are:
**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call**
**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here**
I saw this link and there are some suggestion to switch of warnings like "If you want to disable the deprecation warnings, please use a command-line argument -W:no-deprecated or add Warning[:deprecated] = false to your code." but I was thinking on little bit better solution/fix for actionpack v6.0.2.1
To suppress warnings like:
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
For now, simply prefix/pass the RUBYOPT environment variable to your rails commands:
RUBYOPT='-W:no-deprecated -W:no-experimental' rails server
or
RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate
This may not work with earlier versions of ruby.
For backward compatibility with earlier versions of ruby prefix it with RUBYOPT='-W0' instead.
example:
RUBYOPT='-W0' bundle exec rspec
If you don't want to prefix this each time you run a command, then simply add this to the last line of your .zshrc or .bashrc (whatever you're using):
export RUBYOPT='-W:no-deprecated -W:no-experimental'
or
export RUBYOPT='-W0'
Also see last point of the notes here:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-and-
Update to Rails 6.0.3, they fixed the warnings.
If you still get warnings, it's other libraries (see if there are fixed versions or submit a patch) or your own code (how to fix it).
Obviously it will take some time to for ruby team to remove all this warning in next ruby version. For now the command in your terminal
`RUBYOPT='-W:no-deprecated' rails s`
on my basic, plain new rails 6.0.2.1 && ruby 2.7.0 project remove these two warnings lines above in a question.
Also, with command
RUBYOPT='-W:no-experimental' rails s
you will hide warnings about experimental features.
You can combine these two in one command like:
RUBYOPT='-W:no-deprecated -W:no-experimental' rails s
However, I tried these commands inside my old project built with rails 5.2 and ruby 2.6.4 later upgraded to rails 6.0.1 and they didn't worked well on for all warnings messages I got from different rails Active* modules and ruby gems.
Probably we will need some time for upgrading code and gems for new latest stuff.

can't start default server on rails

I'm new in rails. I follow the tutorial on the web of rails. After install sqlite3, I try start the server, but I can't. the terminal show me this code
invitado#Home:~/blog$ bin/rails server
=> Booting Puma
=> Rails 5.2.2 application starting in development
=> Run `rails server -h` for more startup options
/usr/lib/ruby/vendor_ruby/rack/mime.rb:54: warning: already initialized constant Rack::Mime::MIME_TYPES
/var/lib/gems/2.3.0/gems/rack-2.0.6/lib/rack/mime.rb:49: warning: previous definition of MIME_TYPES was here
/usr/lib/ruby/vendor_ruby/rack/file.rb:15: warning: already initialized constant Rack::File::ALLOWED_VERBS
/var/lib/gems/2.3.0/gems/rack-2.0.6/lib/rack/file.rb:17: warning: previous definition of ALLOWED_VERBS was here
/usr/lib/ruby/vendor_ruby/rack/file.rb:16: warning: already initialized constant Rack::File::ALLOW_HEADER
/var/lib/gems/2.3.0/gems/rack-2.0.6/lib/rack/file.rb:18: warning: previous definition of ALLOW_HEADER was here
/usr/lib/ruby/vendor_ruby/rack/response.rb:23: warning: already initialized constant Rack::Response::CHUNKED
/var/lib/gems/2.3.0/gems/rack-2.0.6/lib/rack/response.rb:26: warning: previous definition of CHUNKED was here
Exiting
/var/lib/gems/2.3.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:76:in `block in load_missing_constant': uninitialized constant Rack::Session::Abstract::Persisted (NameError)
from /var/lib/gems/2.3.0/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in without_bootsnap_cache
and so on with a lot of lines. If anyone can help me I appreciate it. Thank you!
A better choice is to install rvm or rbenv to handle your ruby/gems versions for your app.
Just follow this link http://railsapps.github.io/installrubyonrails-ubuntu.html
I think it will help you. :)

After upgrading to ruby 2.5.1 the rails server failing with "warning: constant ::Fixnum is deprecated"

All,
After upgrading my Ruby to 2.5.1 and Rails version to 4.2.5, when I try to start my rails server I get the following message below and it crashes. I've seen a couple of links about the error, but those didn't prevent the rails server from starting up. Is there another way besides upgrading to 5.0.2? Also my Gem version is 2.7.6.
rails server
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-4.2.5/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
/usr/local/lib/ruby/gems/2.5.0/gems/activesupport-4.2.5/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
Traceback (most recent call last):
You can try using an earlier version of ruby. I'm on rails 4.2.7.1 with ruby 2.3.1 and all is fine.
Alternatively, and according to this issue on Github, you can upgrade to rails 4.2.8 or higher for ruby 2.4 (and presumably higher) support.

Resources