Search code examples
ruby-on-rails

Ruby on rails: Error when ceating a new application


I am trying to create a new rails app but running into an error.

Rails command used: rails new abc -d mysql

Ruby version: 2.7.0

Rails version: 7.1.3.2 (I have also tried with 7.1.5.1)

Error:

bin/rails aborted!
SyntaxError: /var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record/attribute_methods.rb:482: syntax error, unexpected (...
...   def method_missing(name, ...)
...                            ^~~
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record/attribute_methods.rb:491: unexpected ...
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record/attribute_methods.rb:495: syntax error, unexpected ')'
...  return public_send(name, ...)
...                              ^
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record/attribute_methods.rb:551: syntax error, unexpected end-of-input, expecting `end'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record.rb:128:in `<module:ActiveRecord>'
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record.rb:38:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/activerecord-7.1.5.1/lib/active_record/railtie.rb:3:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/all.rb:20:in `block in <main>'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/all.rb:18:in `each'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/all.rb:18:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/akanksha/Work/Projects/materials_generator/abc/config/application.rb:3:in `<main>'
/home/akanksha/Work/Projects/materials_generator/abc/Rakefile:4:in `require_relative'
/home/akanksha/Work/Projects/materials_generator/abc/Rakefile:4:in `<main>'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/commands/rake/rake_command.rb:43:in `block in with_rake'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/command.rb:156:in `invoke_rake'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/command.rb:73:in `block in invoke'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/command.rb:149:in `with_argv'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/command.rb:69:in `invoke'
/var/lib/gems/2.7.0/gems/railties-7.1.5.1/lib/rails/commands.rb:18:in `<main>'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/var/lib/gems/2.7.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)

The line that is printed before this error in the console:

rails importmap:install

Does anyone know the reason for this error or what I can do to resolve this?


Solution

  • If you look closely at the error, it's happening because of ... (argument forwarding). While it was introduced in ruby 2.7.0, it initially only allowed fowarding all arguments or nothing, e.g. def method_missing(...) it couldn't be a leading argument, then in ruby 3.0.0 they supported it being a leading argument, e.g. def method_missing(name, ...), to solve your issue, either upgrade ruby to 3.x or downgrade rails (I wouldn't recommend downgrading to a version below 7.x since 6.x is no longer maintained.

    TL;DR:

    You can do one of the following,

    • Upgrade to Ruby 3.x (Recommended)
    • Downgrade to Rails 6.x (Not recommended since it is no longer maintained)

    References,

    [ruby-lang] Ruby 3.0.0 Release Notes

    [rubyreferences] Ruby 3.0.0 Changes