简体   繁体   中英

How do you gain access to the helper methods inside the controller with Rails

I want to use a method i have in my helper inside my controller. I don't know how to use the view_context which i've heard could do the trick

As apneadiving said, make it a controller method and make that a helper method.

application_controller.rb

  helper_method :do_stuff

  def do_stuff
    #this method is available in all controllers and views

I vote for @apneadiving's idea. But here goes:

class SomeController < ApplicationController
  include SomeHelper
end

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