2016-12-16 21 views
0

我試圖跳過爲我的訂閱控制器設計身份驗證,但無濟於事。我的註冊控制器和會話控制器skip_before_filter都可以工作,但不是我剛剛添加的訂閱控制器。我究竟做錯了什麼?Rails - 跳過設計身份驗證不起作用

class V1::SubscriptionsController < ApplicationController 
skip_before_filter :authenticate_user! 
skip_before_filter :verify_authenticity_token, if: :json_request? 


def create 

    @subscription = Subscription.new(subscription_params) 

    if @subscription.save 
     render json: @subscription, status: :created 
    else 
     render json: @subscription.errors, status: :unprocessable_entity 
    end 
end 

private 

def subscription_params 
    params.require(:subscription).permit(:subscription_email) 
end 
end 

我的應用程序控制器

class ApplicationController < ActionController::API 
    include CanCan::ControllerAdditions 
    include ActionController::RespondWith 
    include ActionController::Serialization 

    acts_as_token_authentication_handler_for User 

    rescue_from CanCan::AccessDenied do |exception| 
    respond_to do |format| 
     format.json { render nothing: true, status: :forbidden } 

    end 
    end 
end 

我的路線

Rails.application.routes.draw do 

devise_for :users, skip: [:sessions, :registrations, :passwords] 

    api_version(module: "V1", header: { name: "Accept", value: "application/vnd.rolotext.json; version=1" }) do 
    devise_scope :user do 
     post 'registrations' => 'registrations#create' 


     post 'sessions' => 'sessions#create' 
     delete 'sessions' => 'sessions#destroy' 

     post 'passwords' => 'passwords#create' 
     patch 'passwords' => 'passwords#update' 
     post 'passwords/check_email' => 'passwords#check_email' 
    end 

    get '/me' => "users#me" 
    patch '/me' => 'users#update' 
    delete '/me' => 'users#destroy' 


    resources :cards, except: [ :new, :edit] 
    patch '/logos' => 'logos#update' 
    resources :logos, except: [ :new, :edit, :destroy ] 
    resources :uploads 
    post '/subscriptions' => "subscriptions#create" 

    end 
end 

任何幫助將是MUCHO讚賞

回答

0

,如果我想在我的用戶控制我通常添加此從身份驗證中排除某些頁面:

before_filter :authenticate_user!, except: [:sessions, :registrations, :passwords]

它應該排除auth除了.. 頁面希望它有幫助。

+0

我試過了,不幸的是它不起作用。正如我前面提到的,其他控制器在跳過身份驗證時沒有問題,並且它們不會在authenticate_user中列爲異常!過濾前。 – duwerq

+0

最後一個想到我想要嘗試將該異常添加到應用程序控制器中。 – liborza