Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

ruby on rails - Setting Devise Login to be root page

I am using the following code for my routes:

devise_for :user, 
  :as => '', 
  :path_names => { 
    :sign_in => "", 
    :sign_out => "logout", 
    :sign_up => "register" 
  }

But when I'm logged out and I goto /logout I get the following error:

No route matches {:action=>"new", :controller=>"devise/sessions"}

How do I setup the root path to be to :sign_in action?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To follow on from the people who are asking about the error Could not find devise mapping for path "/" there is a workaround.

You'll find that there is a clue in your logs which will probably say:

[Devise] Could not find devise mapping for path "/".
This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example:

  devise_scope :user do
    match "/some/route" => "some_devise_controller"
  end

2) You are testing a Devise controller bypassing the router.
   If so, you can explicitly tell Devise which mapping to use:

   @request.env["devise.mapping"] = Devise.mappings[:user]

So I retried the approach but instead wrapping it (as @miccet suggets) inside a scope block:

devise_scope :user do
  root to: "devise/sessions#new"
end

This worked fine for me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...