簡體   English   中英

如何使用 Rails 訪問 controller 中的輔助方法

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

我想在我的 controller 中使用我的助手中的方法。 我不知道如何使用我聽說的 view_context 可以解決問題

正如 apneadiving 所說,將其設為 controller 方法並將其設為輔助方法。

application_controller.rb

  helper_method :do_stuff

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

我投票支持@apneadiving 的想法。 但這里有:

class SomeController < ApplicationController
  include SomeHelper
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM