开发者

How to access cookies method in a Rails 3.0 metal class

I have a Rails 3.0 metal class that is in app/controllers directory.

class FooMetalController < ActionController::Metal

  include ActionController::Cookies
  include ActionController::Helpers::ClassMethods
  include ActionDispatch::Session::CookieStore

  def hit
    unless cookies[:user_id].nil?
      logger.info("Cookies value is : #{cookies[:user_id]}")
      redirect_to "http://www.yahoo.com"
    else
      cookies[:user_id] = { :value => "198", :expires => 180.days.from_now }
      redirect_to "http://www.google.com"
    end
  end

end

When I hit the url with: http://localhost:3000/foo, the hit method gets called. The problem is that it is not able to use the cookies method. I have included modules related to cookies, still I am getting : ActionController::RoutingError (undefined method `helper_method' for开发者_JS百科 error message.

How do I make a Rails metal class recognize the cookies method?


Looking at the source: https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/cookies.rb

It looks like including ActionController::Cookies implicitly calls helper_method when it is included. Try including ActionController::Helpers before ActionController::Cookies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜