Andy Harvey
Andy Harvey

Reputation: 12653

How to use scoped locale + path_prefix with Devise?

In a Rails 3.2 app I'm using Devise with a path_prefix and localization with scoped routes.

#routes.rb
MyApp::Application.routes.draw do
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/  do
    devise_for :admins,  
      path_prefix: 'administration',
    end

   ...other resources
  end
end

While the url for all my other resources is written correctly eg /en/resource/1 in the addressbar, Devise paths are passing the locale as a parameter /administration/admins/registrations/login?locale=en

How do I encourage Devise to use the format /locale/path_prefix/route?

Upvotes: 2

Views: 3116

Answers (1)

user1026130
user1026130

Reputation:

The first line should be replaced with the second line.

devise_for :admins, :path_prefix => "administration"

devise_for :admins, :path => "administration/admins"

So in your example, it would be:

#routes.rb
MyApp::Application.routes.draw do
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/  do
    devise_for :admins, :path => "administration/admins"

   ...other resources
  end
end

For more information on devise_for, check out this link: http://rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper#devise_for-instance_method

Upvotes: 2

Related Questions