【发布时间】:2014-04-30 11:49:11
【问题描述】:
我是Ruby on Rails的新手
在我的项目中,我要求在index 上获取JSON 和HTML 格式。但我只想检查authentication 的HTML 请求而不是JSON 请求。
我使用devise gem,作为authentication。
在我的Controller我设置
skip_before_action :authenticate_user!, only[:index], if: -> { request.format.json? }
def index
@products = Product.all
respond_to do |format|
format.html
format.json { render :json => @products }
end
end
目前JSON 和HTML 请求不要求authentication
我如何做到这一点?
有什么方法可以在format.html { ... } 上查看authentication
提前致谢
【问题讨论】:
标签: ruby-on-rails ruby json authentication devise