60
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

[Rails 4.x] ViewからController名やAction名を参照する方法

View(erb)からController名を参照する

<%= controller.controller_name %>

View(erb)からAction名を参照する

<%= controller.action_name %>

ついでに

Controllerから取得する

controller_name = controller_name  # コントローラ名
action_name = action_name  # アクション名

参考

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
60
Help us understand the problem. What are the problem?