开发者

How do I chain devise_for calls in my route file? - Rails 3.1

I am trying to use OmniAuth, and according to Ryan Bates, I should override the Devise Registration controller by specifying the following devise_for scope in my routes.rb file:

devise_for :users, :controllers => {:registrations => 'registrations'}

However, according to Devise's documentation, if I am to customize the path_names, so instead of doing mydomain.com/users/sign_up/, I can do mydomain.com/register, I would have to do something like this:

devise_for :users, :path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout", :settings => "settings", :newpass => "newpass", :changepass => "changepass" }

I tried to chain both of them like this:

devise_for :users, :controllers => {:registrations => 'registrations'}, :path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout", :settings => "settings", :newpass => "newpass", :changepass => "changepass" }

But that doesn't work. In order for me to go开发者_C百科 to the view in my views/registrations/new.html.erb, I have to go to mydomain.com/users/register. If I go to mydomain.com/register it still serves it from /views/devise/registrations/new.html.erb.

How do I get mydomain.com/register to point to /views/registrations/new.html.erb?

Thanks.


Write this in you routes file instead of adding :path_name

devise_scope :user do
   get "register", :to => "devise/registrations#new"
   get "login", :to => "devise/sessions#new"
   get "logout", :to => "devise/sessions#destroy"
end

_edit2__

If you want to override the controllers then you need to copy the devise controller folder from your gem into your application under app/controllers. In this case You also need to write below lines in routes.rb file. If you don't want to override the default functionality for devise controllers then there is no need to adding below lines in routes.rb file.

devise_for :users, :controllers => {
      :registrations => 'devise/registrations',
      :sessions => 'devise/sessions',
      :passwords => 'devise/passwords',
      :confirmations => 'devise/confirmations',
      :unlocks => 'devise/unlocks'
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜