2

Below code has been failing while upgrading to rails 6.1.3.2 from rails 5.2.3

Project.all.each do |project|
    define_method("is_#{project.name}?".to_sym) { User.current_user.try(:projects) && User.current_user.projects.include?(Project.where(name: project.name).first) }
  end

Also have run the application in console using 'rails console' in windows powershell and commented the above lines giving error: Without commenting in model

irb(main):001:0> User.all
C:/Ruby30/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/associations.rb:1940: warning: already initialized constant User::HABTM_Projects
C:/Ruby30/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/associations.rb:1940: warning: previous definition of HABTM_Projects was here
  Role Load (10.9ms)  SELECT "PROJECTS".* FROM "PROJECTS"
Traceback (most recent call last):
        3: from (irb):1:in `<main>'
        2: from app/models/user.rb:2:in `<top (required)>'
        1: from app/models/user.rb:158:in `<class:User>'
ArgumentError (wrong number of arguments (given 2, expected 1))

After commenting line 158:

irb(main):001:0* User.all
C:/Ruby30/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/associations.rb:1940: warning: already initialized constant User::HABTM_Projects
C:/Ruby30/lib/ruby/gems/3.0.0/gems/activerecord-6.1.3.2/lib/active_record/associations.rb:1940: warning: previous definition of HABTM_Projects was here
  User Load (13.9ms)  SELECT "USERS".* FROM "USERS" /* loading for inspect */ FETCH FIRST :a1 ROWS ONLY  [["LIMIT", 11]]
Traceback (most recent call last):
ArgumentError (wrong number of arguments (given 2, expected 1))

Console is failing in administrator when running 'rails console' in command prompt gives below error:

C:/Ruby30/lib/ruby/3.0.0/reline/config.rb:102:in `expand_path': non-absolute home (ArgumentError)
        from C:/Ruby30/lib/ruby/3.0.0/reline/config.rb:102:in `inputrc_path'
        from C:/Ruby30/lib/ruby/3.0.0/reline/config.rb:119:in `read'
        from C:/Ruby30/lib/ruby/3.0.0/reline.rb:232:in `inner_readline'
        from C:/Ruby30/lib/ruby/3.0.0/reline.rb:175:in `readmultiline'
        from C:/Ruby30/lib/ruby/3.0.0/forwardable.rb:238:in `readmultiline'
        from C:/Ruby30/lib/ruby/3.0.0/forwardable.rb:238:in `readmultiline'
        from C:/Ruby30/lib/ruby/3.0.0/irb/input-method.rb:302:in `gets'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:519:in `block (2 levels) in eval_input'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:721:in `signal_status'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:518:in `block in eval_input'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:202:in `lex'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:174:in `block (2 levels) in each_top_level_statement'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:171:in `loop'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:171:in `block in each_top_level_statement'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:170:in `catch'
        from C:/Ruby30/lib/ruby/3.0.0/irb/ruby-lex.rb:170:in `each_top_level_statement'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:537:in `eval_input'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:472:in `block in run'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:471:in `catch'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:471:in `run'
        from C:/Ruby30/lib/ruby/3.0.0/irb.rb:400:in `start'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:70:in `start'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:19:in `start'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands/console/console_command.rb:102:in `perform'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30/lib/ruby/gems/3.0.0/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in `<top (required)>'
        from bin/rails:9:in `require'
        from bin/rails:9:in `<main>'
  • 1
    Did you only upgrade Ruby on Rails from 5.2.3 to 6.1.3.2, or did you upgrade Ruby at the same time as well? I have the feeling that you did both and Ruby on Rails might not yet be compatible with Ruby 3.x, try downgrading Ruby to the latest 2.x version. – 3limin4t0r Jun 24 '21 at 17:28
  • ruby has to be upgraded to Ruby 3.x. It is the requirement. rails 6.1.3.2 is working with ruby 2.7 but failing in Ruby 3.0 – abhishek Karnani Jun 24 '21 at 17:42
  • 3
    Why do you think upgrading to Ruby 3.x is a requirement? [The specified Ruby version according to to RubyGems is 2.5 or higher.](https://rubygems.org/gems/rails/versions/6.1.3.2) Ruby 3.x changes how parameters are handled. In 3.x you can no longer pass a hash to be handled as keyword arguments, they have to be flattened. eg. `kargs = { key: value }` now has to be passed as `method(**kargs)` instead of `method(kargs)`. This is something that Ruby on Rails 6.1.3.2 might not yet account for. – 3limin4t0r Jun 24 '21 at 17:49
  • I am upgrading my application.. so facing these issues.. Please help me fixing issue in line ''Project.all.each do |project| define_method("is_#{project.name}?".to_sym) { User.current_user.try(:projects) && User.current_user.projects.include?(Project.where(name: project.name).first) } end'' – abhishek Karnani Jun 24 '21 at 17:58
  • What you are doing just seems like six kinds of awful, but strictly speaking I can't reproduce the issue with the code provided with ruby 3.x/rails 6.1.x. So, your root problem is likely somewhere else. The last error (`rails console` failing) is probably unrelated -- check that `$HOME` is set in your environment and set to an absolute path. – rmlockerd Jun 24 '21 at 21:26

0 Answers0