有谁知道我为什么得到
undefined method `my_method' for #<MyController:0x1043a7410>
Run Code Online (Sandbox Code Playgroud)
当我从ApplicationController子类中调用my_method("string")时?我的控制器看起来像
class MyController < ApplicationController
def show
@value = my_method(params[:string])
end
end
Run Code Online (Sandbox Code Playgroud)
和我的帮手
module ApplicationHelper
def my_method(string)
return string
end
end
Run Code Online (Sandbox Code Playgroud)
最后,ApplicationController
class ApplicationController < ActionController::Base
after_filter :set_content_type
helper :all
helper_method :current_user_session, :current_user
filter_parameter_logging :password
protect_from_forgery # See ActionController::RequestForgeryProtection for details
Run Code Online (Sandbox Code Playgroud) 是否可以从控制器调用辅助方法?如果是,如何在Rails 3中执行此操作?