是否有必要在控制器中提及控制器中的私有方法helper_methods?喜欢
class PostsController < ApplicationController
helper_method :check_something
def new
check_something
@post = Post.new
end
def show
@post = Post.find(params[:id])
end
private
def check_something
redirect_to(root_path) and return if something
end
end
Run Code Online (Sandbox Code Playgroud)
声明: helper_method :check_something要求吗?如果是这样的话?
当我从控制器调用私有方法时,操作方法是params私有helper方法还是方法?
我认为你误解了'helper_method'的概念.
helper_method 用于使控制器方法充当辅助模块中的方法
因此,在您的控制器中,您始终可以在没有" helper_method"部分的情况下访问您的私有方法
如果您将控制器方法添加为辅助方法,就像您已经完成的那样,在视图中您可以简单地调用它
对于你的第二个问题,yes params hash可以通过控制器私有方法访问
HTH