问题
I began troubleshooting my "sudden" broken routes problem in this SO question: Devise /users/sign_in redirecting to wrong controller and with help I was able to isolate the issue to the upgrade from journey 1.0.3 to 1.0.4 that occurred when I updated to rails 3.2.7.
As you know, we need to be at rails 3.2.8, to apply important security fixes, but this means I must use journey 1.0.4, which breaks my devise routes. For instance, my custom new_user_session route is welcome#welcome, but it is being decoded to devise/welcome#welcome which does not exist.
Has anybody else run into this love triangle, and if so how did you make journey 1.0.4 play nice with devise?
The routes that are broken (root and devise routs:
devise_for :users
devise_scope :user do
get "/login" => "devise/sessions#new"
get "/register" => "devise/registrations#new"
end
match '/signout/confirm' => 'signouts#confirm'
root :to => "welcome#welcome"
================================================================
Edit: 2012-09-05
Solution:
I found the offending LOC:
link_to_unless_current( logo_image, { :controller => 'welcome', :action => 'welcome' } )
I changed it to:
link_to_unless_current( logo_image, { :controller => '/welcome', :action => 'welcome' } )
to no avail.
Out of curiosity, I changed it to:
link_to( logo_image, { :controller => '/welcome', :action => 'welcome' } )
and that worked, as did:
link_to( logo_image, { :controller => 'welcome', :action => 'welcome' } )
So the last thing I tried was:
link_to_unless_current( logo_image, root_path )
which worked, and all is now well with the universe.
POSTMORTEM:
My inexperience with the rails documentation led me to infer that while link_to()
would accept root_path as a parameter, that link_to_unless_current()
would not. It wasn't until I looked at the source code for the methods, that I found (and should have assumed all along) that link_to_unless_current()
is built on top of link_to_unless()
, which in turn is built on top of link_to()
.
Big Thank You to the folks who helped out in this thread and the previous one.
回答1:
I had a similar problem with journey 1.0.4 and devise in my little Rails learning project, where loading the devise sign-up page failed with a routing error. I was able to fix the problem by changing the links that were added to the site's header by views/layouts/application.html.erb and its partials.
I changed links like this:
<%= link_to 'Home', {:controller=>'welcome', :action=>'index'} %>
to:
<%= link_to 'Home', {:controller=>'/welcome', :action=>'index'} %>
and routing started to work.
来源:https://stackoverflow.com/questions/12163950/how-to-fix-broken-devise-routing-under-journey-1-0-4