我正在努力使rails网络应用程序和rails API一起用于移动应用程序。为此目的,我用的是“设计”和“设计象征”。
我配置路由,因为它是用Devise编写的,这样我就可以有常规设计和设计auth令牌的路由。
我有两个问题:
可能的解决方案:我创建了API控制器继承的间隔ApiApplicationController。
class ApiApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
protect_from_forgery with: :null_session
end可能的解决方案:我可以在ApplictionController和ApiApplicationController if: Proc.new { |c| c.request.format == 'application/json' }之后添加protect_from_forgery with: :null_session
发布于 2016-09-02 06:18:58
我曾经把同样的问题交给你,我的解决方案目前正在起作用:
# application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session, if: ->{request.format.json?}
end
# api_application_controller.rb
class ApiApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
before_action :authenticate_user!
endhttps://stackoverflow.com/questions/39280900
复制相似问题