0
0

More than 1 year has passed since last update.

componentでapplication_helperを読み込みたい

Posted at

状況

Rails6.1から導入された、viewcomponentを使用していたところhoge_component.rbで
application_helperを読み込めず困っていました...💦

実行環境

ruby 3.0.1p64
Rails 6.1.4.6

解決方法

Componentの最初にinclude ApplicationHelperを記述する

class HogeComponent < ViewComponent::Base
  include ApplicationHelper
  ...
end

学び

gemや今回のようなapplicationhelperが使用出来ないときは、Helperが読み込めないことがほとんどでした(これで何十時間溶かしてきたことか...😭)
そういう時は一度include ~~Helperとして見ると解決することが多いです!!
エラーが出ると脳死で延々とググってしまう癖があるので、なぜそのエラーが発生しているのかをできるだけ細分化してワンステップごとに解決できるようにしていきます。
焦らない、焦らない...keep calm.....

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