I just generated all the views for devise, and I'm starting to customize the login screen. It works great except for all the links that are generated on the sign in page start with "/devise".
- Why is it doing that? Seems like odd default behaviour
- How do I stop it from adding /devise to every link_to()?
My routes file:
devise_for :users
get "/webpages/:page" => "webpages#show", :as => :show_webpage
root :to => "webpages#index"
My 'rake routes'
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
show_webpage GET /webpages/:page(.:format) {:controller=>"webpages", :action=>"show"}
root /(.:format) {:controller=>"webpages", :action=>"index"}
The error message I get when I try and render a page that comes from the devise controller:
ActionController::RoutingError in Devise/sessions#new
Showing /home/egervari/Projects/training/app/views/layouts/application.html.erb where line #21 raised:
No route matches {:controller=>"devise/webpages", :action=>"show", :page=>"tour"}
Extracted source (around line #21):
18: </a>
19: </li>
20: <li>
21: <%= link_to("Tour", :controller => "webpages", :action => "show", :page => "tour") %>
22: </li>
23: <li>
24: <%= link_to("Why Use Us?", :controller => "webpages", :action => "show", :page => "why") %>
As you can see above, it's trying to add "devise/" to my link. This is not what I want at all.
All links/forms targeted to devise are expected to start with "/devise". See the routes generated by devise below. Why do you want change this behavior? Is it not working? Or do you need/want to customize the devise controllers?
In newer versions of Rails you can do:
You just append a _path onto the named route that you see when you do a 'rake routes'. Appending _url to the named route will give you the URL string, BTW. Which can be useful.
ian.
I figured it out finally.
Basically what I did was put "/webpages" instead of "webpages" to tell rails that these controllers were not under the "devise" namespace or parent directory.
Is this the appropriate fix? Is there a simpler solution?