简体   繁体   English

相同设计模型的Rails多个URI模式

[英]Rails Multiple URI Pattern for the same Devise Model

I'm using Devise in my project and I originally started it back in 2013 with API Version 1 (api/v1/). 我在项目中使用的是Devise,最初是从2013年使用API​​版本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. 我不必创建版本2(api / v2 /),并且在解决如何创建新的v2路由以进行设计时遇到了问题。

Both /api/v1/ and /api/v2/ are pointing to the same users model, but I have them going through different controllers. / api / v1 /和/ api / v2 /都指向相同的用户模型,但是我让他们通过不同的控制器。 Currently below is what I'm trying, but I get the message "Invalid route name, already in use: 'new_user_session'". 目前,我正在尝试以下操作,但是出现消息“无效的路由名称,已经在使用:'new_user_session'”。

控制器设置

The scoped route for /api/v1/ / 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/ / 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. 您需要在旁边或范围内使用namespace

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 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... 那么您的路线将是new_v1_user_sessionnew_v2_user_session ,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM