I have this in views/posts/index.html.erb
<% if user_signed_in? %>
<%= link_to('Logout', destroy_user_session_path, :method => 'delete') %>
<% else %>
<%= link_to('Login', new_user_session_path) %>
<% end %>
class PostsController < ApplicationController before_filter :authenticate_user! ....
class UsersController < ApplicationController before_filter :authenticate_user! end
rake routes:
new_user_session GET /usuarios/login(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /usuarios/login(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /usuarios/logout(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /usuarios/secret(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /usuarios/secret/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /usuarios/secret/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /usuarios/secret(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /usuarios/register/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /usuarios/register(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /usuarios/register/cmon_let_me_in(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /usuarios/register/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /usuarios/register(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /usuarios/register(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"}
POST /posts(.:format) {:action=>"create", :controller=>"posts"}
new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
/posts/:id/categ(.:format) {:controller=>"posts", :action=>"categ"}
/posts/:id/tag_posts(.:format) {:controller=>"posts", :action=>"tag_posts"}
posts_searcharchive /posts/searcharchive(.:format) {:controller=>"posts", :action=>"searcharchive"}
categories GET /categories(.:format) {:action=>"index", :controller=>"categories"}
POST /categories(.:format) {:action=>"create", :controller=>"categories"}
new_category GET /categories/new(.:format) {:action=>"new", :controller=>"categories"}
edit_category GET /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"}
category GET /categories/:id(.:format) {:action=>"show", :controller=>"categories"}
PUT /categories/:id(.:format) {:action=>"update", :controller=>"categories"}
DELETE /categories/:id(.:format) {:action=>"destroy", :controller=>"categories"}
comments GET /comments(.:format) {:action=>"index", :controller=>"comments"}
POST /comments(.:format) {:action=>"create", :controller=>"comments"}
new_comment GET /comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_comment GET /comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
comment GET /comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /comments/:id(.:format) {:action=>"update", :con开发者_JS百科troller=>"comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
countpages GET /countpages(.:format) {:action=>"index", :controller=>"countpages"}
POST /countpages(.:format) {:action=>"create", :controller=>"countpages"}
new_countpage GET /countpages/new(.:format) {:action=>"new", :controller=>"countpages"}
edit_countpage GET /countpages/:id/edit(.:format) {:action=>"edit", :controller=>"countpages"}
countpage GET /countpages/:id(.:format) {:action=>"show", :controller=>"countpages"}
PUT /countpages/:id(.:format) {:action=>"update", :controller=>"countpages"}
DELETE /countpages/:id(.:format) {:action=>"destroy", :controller=>"countpages"}
root /(.:format) {:controller=>"posts", :action=>"index"}
in routes.rb:
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
I got error:
ActionController::RoutingError in Devise/sessions#new
Showing app/views/layouts/application.html.erb where line #16 raised:
No route matches {:controller=>"devise/posts"}
this is root: root :to => "posts#index" , when i hit http://0.0.0.0:3000 , it redirects to http://0.0.0.0:3000/usuarios/login and got this error,
app/views/layouts/application.html.erb:16:in `_app_views_layouts_application_html_erb__647429696_90155120__982654953'
The problem is because you change the default route for user : devise_for :users, :path => "usuarios",
I mean, now all your routes will be _usuario_
i.e. :
<% if usuario_signed_in? %>
<%= link_to('Logout', destroy_usuario_session_path %>
<% else %>.....
精彩评论