0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rails6でScaffoldがエラーになる

Posted at

環境

Rails 6.1.5
テンプレート:slim-rails 3.4.0

viewのテンプレートをSlimにしている場合Scaffoldでエラーになる

いざScaffoldしようと思って

$ rails g scaffold hoge a:string b:integer

とすると、modelとcontrollerは作成されるが、

in `model_resource_name': wrong number of arguments (given 1, expected 0) (ArgumentError)
略
in `template'

変なエラーが出てviewが作成されない。

色々調べてたどり着いたのがこちら

Rails scaffold views throws wrong number of arguments error

どうやら、rails6にrails7に対応している最新版のslim-rails3.4.0が入ってしまうとよろしくないらしい。

解決方法

slim-railsのバージョンを3.3.0に固定する

Gemfile
#バージョン無しだと3.4.0がインストールされてしまうため3.3.0にバージョン固定
gem 'slim-rails', '3.3.0'

bundle install後、再度scaffold

$ bundle install
$ rails g scaffold hoge a:string b:integer

invoke    slim
      create      app/views/hoge
      create      app/views/hoge/index.html.slim
      create      app/views/hoge/edit.html.slim
      create      app/views/hoge/show.html.slim
      create      app/views/hoge/new.html.slim
      create      app/views/hoge/_form.html.slim

エラーが出なくなった!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?