Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 控制器未在\u筛选器之前继承_Ruby On Rails_Ruby_Actioncontroller - Fatal编程技术网

Ruby on rails 控制器未在\u筛选器之前继承

Ruby on rails 控制器未在\u筛选器之前继承,ruby-on-rails,ruby,actioncontroller,Ruby On Rails,Ruby,Actioncontroller,所以我有ApplicationController.rb: class ApplicationController < ActionController::Base protect_from_forgery def decode_email params[:email] = URI::decode(params[:email]) end end class UsersController < ApplicationController before_fil

所以我有ApplicationController.rb:

class ApplicationController < ActionController::Base
  protect_from_forgery

  def decode_email
    params[:email] = URI::decode(params[:email])
  end
end
class UsersController < ApplicationController
  before_filter :decode_email, only: [:show]

  def show
    #blah blah
  end
end
class ApplicationController
然后是UsersController.rb:

class ApplicationController < ActionController::Base
  protect_from_forgery

  def decode_email
    params[:email] = URI::decode(params[:email])
  end
end
class UsersController < ApplicationController
  before_filter :decode_email, only: [:show]

  def show
    #blah blah
  end
end
class UsersController
现在,点击show action将导致:

undefined local variable or method 'decode_email' for #<UsersController:0x007fb5f216a710>
未定义的局部变量或方法“解码电子邮件”#
为什么不继承该方法,以便将其正确用作before\u筛选器?

class ApplicationControllerclass ApplicationController < ActionController::Base
  protect_from_forgery

  private
    def decode_email
      params[:email] = URI::decode(params[:email])
    end
end
保护你不被伪造 私有的 def解码电子邮件 params[:email]=URI::decode(params[:email]) 结束 结束
对我有用

这应该有用。难道
decode\u email
被误认为是一种私人方法吗?您的
应用程序控制器中是否有
private
?它不工作完全是因为
private
-它应该是私有的。您使用的是哪个ruby和rails版本?你尝试重新启动你的服务器了吗?@QumaraSixOneTour,不,它不应该是私有的!它应该是公共的或受保护的,但不是私有的。看起来它应该可以工作,但是可以尝试在
ApplicationController.rb
中的方法上方添加
helper\u方法:decode\u email