LoginSignup
2
1

More than 5 years have passed since last update.

Controller内でのHelperメソッドの呼び出しについて

Posted at

RailsのHelper内で定義したメソッドは、デフォルトでView内で使用することはできるが、
Controller内では使用することが出来ないようになっている。

これをController内でも使用できるようにするには、application_controller.rbで
Helperをincludeしてやれば良い。

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  include HogeHelper # この行を追加
end

上記の場合であると、controller内でHogeHelperのメソッドを使用することができるようになる。

参考:Ruby on Railsチュートリアル 8章 8.2 ログイン

2
1
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
2
1