2013-08-15 5 views
7

पर उपयोगकर्ताओं को भेज रहा है मेरे पास उपयोगकर्ता पंजीकरण और लॉगिन करने के लिए जेएसओएन एपीआई का उपयोग करने के लिए मेरे रेल ऐप और डिवाइसेज सेट अप हैं।डिवाइसेज: पासवर्ड रीसेट ईमेल में edit_password_url यूआरएल/एपीआई/वी 1/

http://localhost:3000/api/v1/password/edit?reset_password_token=ZzyPCgmspN2964ENUkSS 

यह api/v1/ नहीं करना चाहिए था जब, और उन्हें करने के लिए भेजना चाहिए:

http://localhost:3000/password/edit?reset_password_token=ZzyPCgmspN2964ENUkSS 

मैं देख रहा है एक पक्ष प्रभाव है कि पासवर्ड रीसेट ईमेल के edit_password_url गलती से उन भेज रहा है करने के लिए है , लेकिन यह पता नहीं लगा सकता कि इसे कहां ठीक किया जाए।

मेरे द्वारा बनाए गए निम्न:

Api::V1::SessionsController < Devise::SessionsController 

और

Api::V1::RegistrationsController < RegistrationsController 

मैं एक नियमित RegistrationsController कि वसीयत से विरासत, लेकिन नहीं एक नियमित रूप से SessionsController है, तो मैं बस वहाँ वसीयत से सीधे वारिस ।

सहायता के लिए धन्यवाद!

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

routes.rb

namespace :api, defaults: {format: 'json'} do 
    namespace :v1 do 
     resources :users 
     devise_for :users, :path => '', path_names: {sign_in: "login", sign_out: "logout"}, 
             controllers: { omniauth_callbacks: "authentications", registrations: "registrations"} 
    end 
    end 

devise_for :users, :path => '', path_names: {sign_in: "login", sign_out: "logout"}, 
            controllers: { omniauth_callbacks: "authentications", registrations: "registrations"} 

    resources :users 

संपादित करें 2: rake routes उत्पादन

 new_api_v1_user_session GET  /api/v1/login(.:format)         api/v1/sessions#new {:format=>"json"} 
      api_v1_user_session POST  /api/v1/login(.:format)         api/v1/sessions#create {:format=>"json"} 
    destroy_api_v1_user_session DELETE /api/v1/logout(.:format)         api/v1/sessions#destroy {:format=>"json"} 
api_v1_user_omniauth_authorize GET|POST /auth/:provider(.:format)         authentications#passthru {:provider=>/twitter|facebook/, :format=>"json"} 
    api_v1_user_omniauth_callback GET|POST /auth/:action/callback(.:format)       authentications#(?-mix:twitter|facebook) {:format=>"json"} 
      api_v1_user_password POST  /api/v1/password(.:format)         api/v1/passwords#create {:format=>"json"} 
     new_api_v1_user_password GET  /api/v1/password/new(.:format)        api/v1/passwords#new {:format=>"json"} 
     edit_api_v1_user_password GET  /api/v1/password/edit(.:format)       api/v1/passwords#edit {:format=>"json"} 
           PUT  /api/v1/password(.:format)         api/v1/passwords#update {:format=>"json"} 
cancel_api_v1_user_registration GET  /api/v1/cancel(.:format)         registrations#cancel {:format=>"json"} 
     api_v1_user_registration POST  /api/v1(.:format)           registrations#create {:format=>"json"} 
    new_api_v1_user_registration GET  /api/v1/sign_up(.:format)         registrations#new {:format=>"json"} 
    edit_api_v1_user_registration GET  /api/v1/edit(.:format)          registrations#edit {:format=>"json"} 
           PUT  /api/v1(.:format)           registrations#update {:format=>"json"} 
           DELETE /api/v1(.:format)           registrations#destroy {:format=>"json"} 
         sessions GET  /sessions(.:format)          sessions#index 
           POST  /sessions(.:format)          sessions#create 
        new_session GET  /sessions/new(.:format)         sessions#new 
        edit_session GET  /sessions/:id/edit(.:format)        sessions#edit 
         session GET  /sessions/:id(.:format)         sessions#show 
           PUT  /sessions/:id(.:format)         sessions#update 
           DELETE /sessions/:id(.:format)         sessions#destroy 
       authentications GET  /authentications(.:format)         authentications#index 
           POST  /authentications(.:format)         authentications#create 
      new_authentication GET  /authentications/new(.:format)        authentications#new 
      edit_authentication GET  /authentications/:id/edit(.:format)      authentications#edit 
       authentication GET  /authentications/:id(.:format)        authentications#show 
           PUT  /authentications/:id(.:format)        authentications#update 
           DELETE /authentications/:id(.:format)        authentications#destroy 

       new_user_session GET  /login(.:format)           devise/sessions#new 
        user_session POST  /login(.:format)           devise/sessions#create 
      destroy_user_session DELETE /logout(.:format)           devise/sessions#destroy 
     user_omniauth_authorize GET|POST /auth/:provider(.:format)         authentications#passthru {:provider=>/twitter|facebook/} 
     user_omniauth_callback GET|POST /auth/:action/callback(.:format)       authentications#(?-mix:twitter|facebook) 
        user_password POST  /password(.:format)          devise/passwords#create 
       new_user_password GET  /password/new(.:format)         devise/passwords#new 
      edit_user_password GET  /password/edit(.:format)         devise/passwords#edit 
           PUT  /password(.:format)          devise/passwords#update 
     cancel_user_registration GET  /cancel(.:format)           registrations#cancel 
       user_registration POST /              registrations#create 
      new_user_registration GET  /sign_up(.:format)           registrations#new 
     edit_user_registration GET  /edit(.:format)           registrations#edit 
           PUT /              registrations#update 
           DELETE /              registrations#destroy 

संपादित करें 3:

तो मैं कुछ बात का परीक्षण किया गया है, और में ईमेल टेम्पलेट तैयार करें, पथ edit_password_url वहां है, और बदतर है केएस उपरोक्त गलत यूआरएल उत्पन्न करने के लिए, लेकिन जब मैं rake routes करता हूं, केवल edit_user_password_url मौजूद है।

उत्तर

3

वसीयत नियंत्रक यूआरएल सहायकों दस्तावेज़ को देखते हुए (here पाया जाता है), मैं का उपयोग किया है जाएगा:

edit_password_path(:user) जो edit_user_password_path करने के लिए अनुवाद। pathurl के साथ विनिमय करने योग्य प्रतीत होता है।

मैं 100% कुछ नहीं कर रहा हूँ, लेकिन यह line एक विधि edit_password_path कहा जाता है को परिभाषित करता है, जबकि इस line वसीयत संदर्भ में एक मार्ग बनाता है ...

+0

मुझे एक ही समस्या है, लेकिन मैं यह समझ नहीं सकता कि इसका उपयोग कैसे करें .. क्या मुझे कोई मौका मिल सकता है एक सलाह –

1

आप पोस्ट नहीं किया है अपने routes.rb लेकिन मैं आपको URL में api/v1/ बिना 'एपीआई/V1/RegistrationsController' के लिए रूट करने के लिए /password/edit चाहते अनुमान लगा रहा हूँ?

यदि हां, तो आपको डीएसएल को रूट करने के module विकल्प का उपयोग करने की आवश्यकता है। इस तरह:

scope module: 'api/v1/' do 
    resources :sessions, :registrations 
end 

बेशक आप devise_for कॉल में ऊपर एकीकृत करने के लिए की जरूरत है। मैं एक वसीयत विशेषज्ञ, नहीं हूँ मैं अनुमान लगा रहा हूँ, अगर आप इस तरह devise_scope बजाय scope उपयोग करने के लिए की आवश्यकता होगी:

devise_scope module: 'api/v1/' do 
    resources :sessions, :registrations 
end 

नोट: यदि ऊपर काम नहीं करता। अपने routes.rb के साथ वापस पोस्ट करें। हम इसे ठीक करने में आपकी सहायता करेंगे

+0

सहायता के लिए धन्यवाद! मैंने अभी अपने मार्ग पोस्ट किए हैं। अगर आपको इसकी आवश्यकता है तो मुझे बताएं। मैं 'रेक मार्ग' – Arel

+0

से प्रासंगिक आउटपुट भी पोस्ट करूंगा 'devise_scope' को जोड़ना आउटपुट को ठीक नहीं करता है और ईमेल भेजने के बाद रूटिंग त्रुटि उत्पन्न करता है:' अनियमित स्थिर सत्र नियंत्रक ' – Arel

+0

बस मेरे मार्ग पोस्ट किए गए। आपको किसी और चीज़ की ज़रुरत हो तो मुझे बताएं। मुझे समझ में नहीं आ रहा है कि यह क्यों हो रहा है, क्योंकि मुझे लगता है कि नियमित रूप से 'edit_user_password' और' edit_api_v1_user_password' – Arel

0

तो, आश्चर्यजनक रूप से, मुझे तैयार मेलर टेम्पलेट में पथ बदलने की आवश्यकता है। मैंने इसे edit_password_url से बदल दिया जो यूआरएल उत्पन्न करने के लिए काम करता था, लेकिन rake routes आउटपुट में edit_user_password_url में दिखाई नहीं दिया जो मैंने अपने rake routes आउटपुट में पाया।

मुझे यह जानना अच्छा लगेगा कि edit_password_url ने काम किया है, भले ही यह rake routes आउटपुट में दिखाई नहीं दे रहा है, और किसी ऐसे व्यक्ति को सही उत्तर देने के लिए खुश हूं जो मुझे बता रहा है कि मेरे साथ क्या हो रहा है।

1

मार्गों है कि आप इस प्रयास करना चाहिए उत्पन्न कर रहे हैं के अनुसार। मेरे मामले में यह ठीक काम कर रहा है। इसे आज़माएं:

edit_user_password_url(reset_password_token: @token) 
+0

आप इसे बैकटिक्स में डालकर कोड प्रारूपित कर सकते हैं (') – amenthes

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