There is underscore
method in ActiveSupport::Inflector
( http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore ). But it is not available in both erb view and rails controller. How can we make it available in view or in rails controller?
This method is added to String. You should be able to call it on any String object, in any context (controller, view, etc.) assuming you've loaded ActiveSupport
If you are using rails 4 you should do the following
go to the controler then follow this example:
def new
@about = About.new
@delete_me = 'EggsAndHam'.underscore
end
you can call the @delete_me on your view
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.