1

从 rails 5.2.3 升级到 rails 6.1.3.2 时,以下代码一直失败

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

还使用 windows powershell 中的“rails console”在控制台中运行应用程序,并评论了上面的行给出错误:没有在模型中评论

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))

在评论第 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))

在命令提示符下运行“rails 控制台”时,控制台在管理员中失败,出现以下错误:

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>'
4

0 回答 0