Home > Mobile >  Rails scaffold views throws wrong number of arguments error
Rails scaffold views throws wrong number of arguments error

Time:04-08

I cannot scaffold any views. It worked before, but suddenly it doesn't work anymore. The controller and models get generated correctly, it only fails when it comes to the views. Only scaffolding the views also doesn't work.

I always get the following 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)

All I typed in was rails g scaffold Customer first_name:string last_name:string. I already re-installed railties and the other gems mentioned, because maybe they failed, but that didn't seem to be the case.

What is the problem?

Edit: It might be important to say that I use slim.

CodePudding user response:

For rails 6 downgrade slim-rails to 3.3.0.

3.4.0 uses new generator templates for Rails 7.

This method in particular causes the problem: https://github.com/rails/rails/blob/v6.1.5/railties/lib/rails/generators/named_base.rb#L150

when slim calls it in https://github.com/slim-template/slim-rails/blob/v3.4.0/lib/generators/slim/scaffold/templates/index.html.slim.tt#L9

  • Related