Redirect not working

前端 未结 2 1815
难免孤独
难免孤独 2021-01-19 21:13

I have this line in my votes controller:

before_filter :authenticate

So when I vote while logged out, it should fail this filter.

M

2条回答
  •  悲哀的现实
    2021-01-19 21:57

    Since the request that is causing problems is ajax try adding a check within your before_filter to whether the request is js.

    if request.xhr?
        render :text => "document.location = '#{login_path}';", :layout => false
    else
      redirect_to login_path, ...
    end
    

提交回复
热议问题