I'm using Devise in my project and I originally started it back in 2013 with API Version 1 (api/v1/). I'm not having to create a version 2 (api/v2/) and I'm having issues figuring out how to go about creating the new v2 routes for devise.
Both /api/v1/ and /api/v2/ are pointing to the same users model, but I have them going through different controllers. Currently below is what I'm trying, but I get the message "Invalid route name, already in use: 'new_user_session'".
The scoped route for /api/v1/
scope '/api' do
scope '/v1' do
devise_for :users, :controllers => {:registrations => "devise/v1/users_registrations",
:sessions => "devise/v1/users_sessions",
:passwords => "devise/v1/users_passwords"}
end
end
The scoped route for /api/v2/
scope '/api' do
scope '/v2' do
devise_for :users, :controllers => {:registrations => "devise/v2/users_registrations",
:sessions => "devise/v2/users_sessions",
:passwords => "devise/v2users_passwords"}
end
Any and all help will be greatly appreciated. Thank you
You need to use a namespace
along-side or instead of the scope.
Right now those scopes will change the location of the files themselves yet do not update the actual pathing names so you are getting a duplicate error.
IE
scope :api do
namespace :v1 do
devise_for :users, controllers: {registrations: "devise/v1/users_registrations",
sessions: "devise/v1/users_sessions",
passwords: "devise/v1/users_passwords"}
end
end
scope :api do
namespace :v2 do
devise_for :users, controllers: {registrations: "devise/v2/users_registrations",
sessions: "devise/v2/users_sessions",
passwords: "devise/v2/users_passwords"}
end
end
Then your routes would be new_v1_user_session
and new_v2_user_session
, etc...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.