Rails 脚手架视图抛出错误数量的参数错误

Rails scaffold views throws wrong number of arguments error

我无法搭建任何视图。之前还可以,突然就不行了。控制器和模型正确生成,只有在涉及视图时才会失败。仅搭建视图也不起作用。

我总是收到以下错误:

      invoke    slim
      create      app/views/customers
Traceback (most recent call last):
        70: from -e:1:in `<main>'
        69: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
        68: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
        67: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
        66: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
        65: from /Users/sam/projects/restaurant/bin/rails:9:in `<main>'
        64: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
        63: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        62: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        61: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/commands.rb:18:in `<main>'
        60: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/command.rb:46:in `invoke'
        59: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/command/base.rb:69:in `perform'
        58: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        57: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        56: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        55: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/commands/generate/generate_command.rb:26:in `perform'
        54: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators.rb:276:in `invoke'
        53: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        52: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
        51: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
        50: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
        49: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
        48: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
        47: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        46: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        45: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:134:in `_invoke_from_option_scaffold_controller'
        44: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:266:in `_invoke_for_class_method'
        43: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/shell.rb:68:in `with_padding'
        42: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:277:in `block in _invoke_for_class_method'
        41: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:116:in `invoke'
        40: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
        39: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
        38: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
        37: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
        36: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
        35: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        34: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        33: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:134:in `_invoke_from_option_template_engine'
        32: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:266:in `_invoke_for_class_method'
        31: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/shell.rb:68:in `with_padding'
        30: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:274:in `block in _invoke_for_class_method'
        29: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:274:in `instance_exec'
        28: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb:26:in `block in <class:ScaffoldControllerGenerator>'
        27: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:116:in `invoke'
        26: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
        25: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
        24: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
        23: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
        22: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
        21: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        20: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        19: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/slim-rails-3.4.0/lib/generators/slim/scaffold/scaffold_generator.rb:9:in `copy_view_files'
        18: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/slim-rails-3.4.0/lib/generators/slim/scaffold/scaffold_generator.rb:9:in `each'
        17: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/slim-rails-3.4.0/lib/generators/slim/scaffold/scaffold_generator.rb:11:in `block in copy_view_files'
        16: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators/named_base.rb:24:in `template'
        15: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators/named_base.rb:45:in `inside_template'
        14: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators/named_base.rb:25:in `block in template'
        13: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:122:in `template'
        12: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:25:in `create_file'
        11: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions.rb:93:in `action'
        10: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:60:in `invoke!'
         9: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/empty_directory.rb:117:in `invoke_with_conflict_check'
         8: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:63:in `block in invoke!'
         7: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:63:in `open'
         6: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
         5: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:53:in `render'
         4: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:131:in `block in template'
         3: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/2.7.0/erb.rb:905:in `result'
         2: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/2.7.0/erb.rb:905:in `eval'
         1: from /Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/slim-rails-3.4.0/lib/generators/slim/scaffold/templates/index.html.slim.tt:9:in `template'
/Users/sam/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/railties-6.0.4.7/lib/rails/generators/named_base.rb:150:in `model_resource_name': wrong number of arguments (given 1, expected 0) (ArgumentError)

我输入的全部是 rails g scaffold Customer first_name:string last_name:string。我已经重新安装了 railties 和提到的其他 gem,因为它们可能失败了,但事实并非如此。

问题是什么?

编辑:说我使用 slim 可能很重要。

对于 rails 6 将 slim-rails 降级为 3.3.0

3.4.0 使用新的生成器模板 Rails 7.

这个方法特别导致问题:https://github.com/rails/rails/blob/v6.1.5/railties/lib/rails/generators/named_base.rb#L150

当 slim 在 https://github.com/slim-template/slim-rails/blob/v3.4.0/lib/generators/slim/scaffold/templates/index.html.slim.tt#L9

中调用它时