[英]How to make underscore method available in view and controller in rails 3.2?
There is underscore
method in ActiveSupport::Inflector
( http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore ). ActiveSupport::Inflector
有underscore
方法( http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore )。 But it is not available in both erb view and rails controller. 但是在erb视图和rails控制器中均不可用。 How can we make it available in view or in rails controller? 我们如何使其在视图或Rails控制器中可用?
This method is added to String. 此方法已添加到String。 You should be able to call it on any String object, in any context (controller, view, etc.) assuming you've loaded ActiveSupport 假设您已加载ActiveSupport,则应该能够在任何上下文(控制器,视图等)中的任何String对象上调用它
If you are using rails 4 you should do the following 如果使用滑轨4,则应执行以下操作
go to the controler then follow this example: 请转到控制程序,然后按照以下示例操作:
def new def新
@about = About.new @about = About.new
@delete_me = 'EggsAndHam'.underscore @delete_me ='EggsAndHam'。下划线
end 结束
you can call the @delete_me on your view 您可以在视图上调用@delete_me
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.