我有一个非常简单的 Controller 来管理我的 Rails 应用程序中的静态页面:
class PagesController < ApplicationController
def home
end
def features
end
def pricing
end
end
我怎样才能让 View 模板返回它自己的名字,这样我就可以做这样的事情:
# pricing.html.erb
<h1><%= my_own_name.capitalize %></h1>
# --> "Pricing"
感谢您的帮助。
最佳答案
The params hash will always contain the :controller and :action keys, but you should use the methods
controller_name
andaction_name
instead to access these values.
<h1><%= action_name.capitalize %></h1>
关于ruby-on-rails - 如何让 Rails View 返回其关联的操作名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23346644/