简体   繁体   中英

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 ). 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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM