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.
Related
with a recent upgrade to rails 7.0.2 from rails 5.2, when ever i start a rails console or a rails server on dev mode i see these warnings
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/digest-3.1.0/lib/digest.rb:20: warning: already initialized constant Digest::REQUIRE_MUTEX
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/digest.rb:6: warning: previous definition of REQUIRE_MUTEX was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:504: warning: previous definition of Socket was here
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/apipie-rails-0.7.0/lib/apipie/extractor/recorder.rb:163: warning: Skipping set of ruby2_keywords flag for process (method accepts keywords or method
For what's its worth the warnings are not present when the application is on Rails 7.0 but only appear when the application is upgraded to Rails 7.0.2
I upgraded rails as per the guide
5.2 -> 6.0 -> 6.1 -> 7.0 -> 7.0.2
May be i missed something, anyways I could fix these? probably these would go away with a ruby / rails subsequent upgrade?
Thanks.
Rails 7.0.1 added some gem dependencies for standard lib stuff that would get removed in ruby 3.0. This unfortunately causes issue with ruby 2.7.6. You can get around this in several ways. Upgrading ruby will also upgrade bundler which fixes the issue. Upgrading bundler without ruby also works but I don't recommend it (better to point to the system version). A more conservative workaround is find the gems that are causing issues and list them on the top of your Gemfile. In my case I had to make sure that the gem version was the same as the default ruby gem version. For example, I had to make the Gemfile have gem "uri", "0.10.0". A good way to debug what is causing these is put this at the top of your Gemfile:
Warning.module_eval do
alias_method :original_warn, :warn
def warn(msg)
if msg.match?(/already initialized constant/)
raise msg
else
original_warn(msg)
end
end
end
That way you get a stacktrace of the places that are requiring stdlib files that also have a conflicting rubygem.
It looks like these are all constants defined in dependency code gems. Running bundle clean --force or updating dependencies with bundle update and then running the bundle clean --force has worked for some when experiencing this issue.
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.
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.
I cloned a Ruby project called Publify (an open-source blogging platform.) However, when I run rails server, I get the following error (I have copy-pasted the info below the image) >
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <class:Simple> at /home/ubuntu/workspace/publify-master/lib/i18n_interpolation_deprecation.rb:24)
=> Booting Thin
=> Rails 5.0.3 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
Exiting
/usr/local/rvm/gems/ruby-2.2.2/gems/actionpack-5.0.3/lib/action_controller/railtie.rb:60:in `block (3 levels) in <class:Railtie>': Invalid option key: page_cache_directory= (RuntimeError)
And then a slew of "From:" statements (as seen in the image.)
My open repo is here, if you would like to take a look: https://gitlab.com/AvBloom98/publify. I did some work to update the gems and such, because they were failing before, thus it is not 1-to-1 with the original Publify Github (found here: https://github.com/publify/publify)
The Publify gem is setting up page caching directory in its configuration but page caching has been deprecated and removed from Rails 4.
However, you can put page caching support back by adding actionpack-page_caching gem into the project, as documented in the Rails guides. From this issue I assume the gem will run nicely in Rails 5, too.
I've tried to find some solution for this, but I really couldn't find anything related with the errors that is appearing to me when I run the rails command:
rails generate model Book title:string summary:text isbn:string
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated
Running via Spring preloader in process 3579
Expected string default value for '--jbuilder'; got true (boolean)
invoke active_record
identical db/migrate/20170104114702_create_books.rb
identical app/models/book.rb
invoke test_unit
identical test/models/book_test.rb
identical test/fixtures/books.yml
Anyone know what may be causing these errors?
This warnings appear because you are using ruby 2.4.0.
This version introduced this change: Unify Fixnum and Bignum into Integer
See here for the announcement: https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/
The warnings come from the activesupport gem which is part of rails and will be fixed in an upcoming release.
For now you can just ignore those warnings.
Update: Rails 5.0.2 has been released, which gets rid of the warnings.
I fixed mine by updating rails
bundle update rails
I assume you're using Rails 5? Check out this link (towards the bottom). Looks like these warnings will go away with release #27458.
If these deprecation warnings in active support are the only warnings you are seeing, you can surpress them by passing a RUBYOPT bash variable with the -W0 option which will silence.
so instead of rails server
try: RUBYOPT="-W0" rails server or RUBYOPT="-W0" bin/rails server
In rails 5.0 you may want to get in the habit of using bin/rails not just rails, since that's the global rails version which may or may not be the same as your local rails version.
I fixed this updating therubyracer gem from version '0.12.2' to '0.12.3'