[RUBY] [Runy On Rails] Active Hash Error NameError in Controller ActiveHash Did you mean? ActiveStorage): Solution

Background and background leading up to the error

I want to create a drop-down list using Active Hash by executing the following command in the terminal.

%rails g model model name--skip-migration

When I created a model for Active Hash and edited each model, I got an error like this one. スクリーンショット 2020-12-17 14.53.04.png

Cause

I didn't install the Active Hash gem in the first place. (It's a rudimentary mistake ...)

approach

Write Active Hash at the bottom of the Gemfile.

Gemfile


gem 'active_hash'

Bundle install and reflect in Gemfile.lock

terminal


% bundle install

Bundle complete! 19 Gemfile dependencies, 81 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

スクリーンショット 2020-12-17 15.08.13.png

I was able to reflect it in the view.

Finally

This time I forgot to add a gem in Active Hash, but surprisingly several times in the past, even though I wanted to use the functions of other gems, I was coding without introducing gems. Sometimes caused an error.

As a future measure, it is necessary to first create an application while checking whether the description is solid in the Gemfile and which gem supports the application before proceeding with coding. I felt that.

Recommended Posts

[Runy On Rails] Active Hash Error NameError in Controller ActiveHash Did you mean? ActiveStorage): Solution
Dealing with NameError: uninitialized constant :: Analyzable error when installing Active Storage in Rails6
[Rails] Solution when migration error occurs in acts-as-taggable-on