找不到帮助方法

问题描述 投票:1回答:3

我有一个 CopiesHelper 模块与方法 cc.

在我 ApplicationController我有

helper :all 
helper_method :cc #just tried putting this in recently

如果在我的另一个控制器中,我尝试使用 cc 方法,我得到

undefined method 'cc' for #<OtherController:0xblublublublub>

我是不是漏掉了一个步骤?

ruby-on-rails helpers
3个回答
0
投票

如果你想使用你的 CopiesHelper 在你的一个控制器中,只需做:

{app_dir}appcontrollersyour_controller.rb)。

class YourController < ApplicationController
    include CopiesHelper

如果你想使用你的 CopiesHelper 在你的应用程序的每个控制器中,只需做:

{app_dir}appcontrollersapplication_controller.rb

class ApplicationController < ActionController::Base
    include CopiesHelper

0
投票

好吧,看来在控制器中一般不使用助记符了!

© www.soinside.com 2019 - 2024. All rights reserved.