2013-05-07 8 views
5

मैं क्या करना चाहता हूं एक बार जब उपयोगकर्ता पुष्टिकरण लिंक पर क्लिक करता है - और उनके खाते को सफलतापूर्वक पुष्टि की जाती है - उन्हें किसी विशेष पथ पर रीडायरेक्ट किया जाना चाहिए, अगर उनके पास कोई विशेष भूमिका है User मॉडल पर after_create कॉलबैक में असाइन किया गया, जिसे सफलतापूर्वक असाइन किया गया है)।उपयोगकर्ता ने पुष्टि की पुष्टि के बाद रीडायरेक्ट पथ को ओवरराइड करना - डेविस

मैं एक RegistrationsController बनाया है:

class RegistrationsController < Devise::RegistrationsController 
    protected 

    def after_sign_up_path_for(resource) 
    if resource.has_role? :seller 
     new_item_path 
    else 
     root_path 
    end 
    end 
end 

लेकिन, यह हमेशा root_path पर रीडायरेक्ट .... भले ही, मैं पुष्टि कर ली है उपयोगकर्ता वास्तव में उस भूमिका में कौन है कि,।

संपादित करें 1

ऐसा लगता है कि पुष्टि अनुरोध RegistrationsController को कभी नहीं भेजा जाता है:

Started GET "https://stackoverflow.com/users/confirmation?confirmation_token=KRwZ7MChtxxq4sxxkDLq" for 127.0.0.1 at 2013-05-07 03:52:56 -0500 
Processing by Devise::ConfirmationsController#show as HTML 
    Parameters: {"confirmation_token"=>"KRwZ7MChtxxq4sxxkDLq"} 
    User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'KRwZ7MChtxxq4sxxkDLq' LIMIT 1 
    (0.1ms) BEGIN 
    (0.5ms) UPDATE "users" SET "confirmation_token" = NULL, "confirmed_at" = '2013-05-07 08:52:56.846852', "updated_at" = '2013-05-07 08:52:56.847730' WHERE "users"."id" = 9 
    (0.8ms) COMMIT 
    (0.1ms) BEGIN 
    (0.4ms) UPDATE "users" SET "last_sign_in_at" = '2013-05-07 08:52:56.852250', "current_sign_in_at" = '2013-05-07 08:52:56.852250', "last_sign_in_ip" = '127.0.0.1', "current_sign_in_ip" = '127.0.0.1', "sign_in_count" = 1, "updated_at" = '2013-05-07 08:52:56.853180' WHERE "users"."id" = 9 
    (0.7ms) COMMIT 
Redirected to http://localhost:3000/ 
Completed 302 Found in 31ms (ActiveRecord: 3.2 

संपादित 2

यह वही मेरी routes.rb

की तरह लग रहा है
devise_for :users, :path_names => { :sign_up => "register", 
             :sign_in => "login", 
             :sign_out => "logout", 
             :settings => "settings" }, 
         :controllers => { :registrations => "registrations" } 

    devise_scope :user do 
    get "login", :to => "devise/sessions#new" 
    get "register", :to => "registrations#new" 
     get "settings", :to => "devise/registrations#edit" 
    get "logout", :to => "devise/sessions#destroy"  
    end 
+0

क्या संसाधन उपयोगकर्ता के बराबर है – ahmet

+0

मुझे विश्वास है। यही वह काम है जो उपयोग करता है। – marcamillion

उत्तर

16

मैं घटना वास्तव में इसे समझ लिया।

मुझे ConfirmationsController.rb कक्षा बनाना था जो डेविस के पुष्टिकरण नियंत्रक को ओवरराइड करता था।

class ConfirmationsController < Devise::ConfirmationsController 
    protected 
    def after_confirmation_path_for(resource_name, resource) 
     if resource.has_role? :seller 
     new_item_path 
     else 
     root_path 
     end 
    end 
end 
मेरी routes.rb में

तब:

devise_for :users, :path_names => { :sign_up => "register", 
             :sign_in => "login", 
             :sign_out => "logout", 
         :settings => "settings" }, 
         :controllers => {:confirmations => "confirmations"} 

    devise_scope :user do 
    get "login", :to => "devise/sessions#new" 
    get "register", :to => "devise/registrations#new" 
    get "settings", :to => "devise/registrations#edit" 
    get "logout", :to => "devise/sessions#destroy"  
    end 

लगता है वह मेरे लिए ठीक काम करने के लिए।

+0

धन्यवाद दोस्त वास्तव में सहायक है –

0

क्या आपने अपने मॉडल user.rb में भूमिका विधि लिखी है। यदि नहीं तो आप भूमिका विधि लिखना चाहिए

या

आप rolify उपयोगकर्ता कक्षा में user.rb में शीर्ष

+0

हां। मैंने सत्यापित किया है कि उपयोगकर्ता की भूमिका है। – marcamillion

0

पर लिख सकते हैं आप डिफ़ॉल्ट

के बजाय ओवरराइड नियंत्रक का उपयोग करने के लिए वसीयत बताने के लिए निम्न लिखित है

config में/routes.rb

devise_for :users, :controllers => {:registrations => "registrations"}

+0

हां। मेरे मार्गों के साथ प्रश्न अपडेट किया गया। आरबी। – marcamillion

+0

पंजीकरण नियंत्रक में load_and_authorize_resource – Murhari

+0

लिख सकते हैं आप http://stackoverflow.com/questions/7624385/custom-registrations-controller-for-devise-not-overriding-create-action – Murhari

संबंधित मुद्दे