2013-08-15 4 views
7

Ho la mia app per rails e Devise set up per utilizzare un'API JSON per eseguire la registrazione e l'accesso dell'utente. Un effetto collaterale è che edit_password_url nell'e-mail di reimpostazione della password viene accidentalmente l'invio agli utenti di:Devise: edit_password_url nella reimpostazione della password, l'e-mail sta inviando gli utenti a url/api/v1/

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

quando non dovrebbe avere api/v1/, e devono rivolgersi a:

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

ho cercato , ma non riesco a capire dove aggiustarlo.

ho creato il seguente:

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

e

Api::V1::RegistrationsController < RegistrationsController 

Ho un RegistrationsController regolare che eredita da concepire, ma non un normale SessionsController, quindi ho solo ereditato direttamente da disposizione testamentaria lì .

Grazie per l'aiuto!

EDIT:

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 

EDIT 2: rake routes uscita

 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 

EDIT 3:

Così ho provato qualche cosa fuori, e nel elaborare un modello di email, il percorso edit_password_url è lì e wor ks per generare l'url sopra sbagliato, ma quando faccio rake routes, esiste solo edit_user_password_url.

risposta

3

Guardando il Devise controller URL Helpers doc (trovato here), avrei usato:

edit_password_path(:user) che si traduce in edit_user_password_path. path sembra essere intercambiabile con url.

io non sono sicuro al 100%, ma questo line definisce un metodo chiamato edit_password_path che tale line crea un percorso nel contesto Devise ...

+0

Ho lo stesso problema, ma non riesco a capire come usare questo .. c'è qualche possibilità che posso ottenere un consiglio –

1

Non hai pubblicato il tuo routes.rb ma suppongo che tu voglia /password/edit per indirizzare a 'Api/V1/RegistrationsController' senza api/v1/ nell'URL?

In caso affermativo, è necessario utilizzare l'opzione module di routing DSL. in questo modo:

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

Naturalmente è necessario integrare in devise_for chiamata. Io non sono un esperto di concepire, sto indovinando, sarà necessario utilizzare devise_scope invece di scope come questo:

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

Nota: Se quanto sopra non funziona. Pubblica di nuovo con il tuo routes.rb. Ti aiuteremo a risolverlo

+0

Grazie per l'aiuto! Ho appena pubblicato le mie rotte. Fammi sapere se ne hai bisogno di più. Pubblicherò anche l'output rilevante da 'rake routes' – Arel

+0

L'aggiunta di' devise_scope' non ha corretto l'output e ha causato un errore di routing dopo l'invio dell'e-mail: 'costante non inizializzata SessionsController' – Arel

+0

Ho appena postato i miei percorsi. Fammi sapere se hai bisogno di qualcos'altro. Non capisco perché questo sta accadendo, dal momento che mi sembra di avere un normale 'edit_user_password' e un' edit_api_v1_user_password' – Arel

0

Quindi, stranamente, avevo bisogno di cambiare il percorso nel modello di mailer di sviluppo. L'ho modificato da edit_password_url che ha funzionato per generare un URL, ma non è stato visualizzato nell'uscita rake routes, a edit_user_password_url che ho trovato nell'uscita rake routes.

Mi piacerebbe sapere perché edit_password_url ha funzionato anche se non viene visualizzato nell'output rake routes e sono più che felice di assegnare la risposta corretta a qualcuno che possa spiegare cosa mi sta succedendo.

1

Secondo gli itinerari che vengono generati si dovrebbe provare questo. Nel mio caso funziona bene. Prova questo:

edit_user_password_url(reset_password_token: @token) 
+0

puoi formattare il codice mettendolo in apice (') – amenthes