我遵循了这个:https://github.com/plataformatec/devise
gem install devise
rails generate devise:install
rails generate devise User
rails generate devise:views
在config / environments / development.rb中添加
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
在app / views / layouts / application.html.erb
中添加<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
routes.rb:
devise_for :users
resources :posts
match "posts/:id/categ" => "posts#categ"
match "posts/:id/tag_posts" => "posts#tag_posts"
match "posts/searcharchive" => "posts#searcharchive"
resources :categories
resources :comments
resources :countpages
root :to => "posts#index"
user.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
end
http://0.0.0.0:3000/users/sign_in我收到错误之后:
ActionController::RoutingError in Devise/sessions#new
Showing app/views/layouts/application.html.erb where line #25 raised:
No route matches {:controller=>"devise/posts"}
Extracted source (around line #25):
22:
23: <div id="header">
24: <h1>
25: <%= link_to 'Home', :controller=>'posts', :action=>'index' %>
26: <%= link_to 'Add Post', :controller=>'posts', :action=>'new' %>
27: <%= link_to 'Add Category', :controller=>'categories', :action=>'new' %>
28: <%= link_to 'Display ategories', :controller=>'categories', :action=>'index' %>
app / vies / layouts / application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Railsecommerce</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="container">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<div id="nav_menu">
<h1>
<% if user_signed_in? %>
<%= link_to('Logout', destroy_user_session_path, :method => 'delete') %>
<% else %>
<%= link_to('Login', new_user_session_path) %>
<% end %>
</h1>
</div>
<div id="header">
<h1>
<%= link_to 'Home', :controller=>'posts', :action=>'index' %>
<%= link_to 'Add Post', :controller=>'posts', :action=>'new' %>
<%= link_to 'Add Category', :controller=>'categories', :action=>'new' %>
<%= link_to 'Display ategories', :controller=>'categories', :action=>'index' %>
</h1>
</div>
<div id="content">
<%= render :partial => "rightsidediv" %>
</div>
<div id="footer">
<%= "user1@Copyright 2011" %>
</div>
</div>
</body>
</html>
完整追踪:
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:425:in `raise_routing_error'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:407:in `rescue in generate'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:396:in `generate'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:454:in `generate'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:482:in `url_for'
actionpack (3.0.9) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.9) lib/action_view/helpers/url_helper.rb:99:in `url_for'
actionpack (3.0.9) lib/action_view/helpers/url_helper.rb:236:in `link_to'
app/views/layouts/application.html.erb:25:in `_app_views_layouts_application_html_erb__426984258_80460110__468457409'
actionpack (3.0.9) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.9) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.9) lib/action_view/template.rb:127:in `render'
actionpack (3.0.9) lib/action_view/render/layouts.rb:80:in `_render_layout'
actionpack (3.0.9) lib/action_view/render/rendering.rb:62:in `block in _render_template'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.9) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.9) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/user1/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.0.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.9) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:39:in `render'
devise (1.4.2) lib/devise/controllers/scoped_views.rb:28:in `render_with_scope'
devise (1.4.2) app/controllers/devise/sessions_controller.rb:9:in `block in new'
actionpack (3.0.9) lib/action_controller/metal/responder.rb:190:in `call'
actionpack (3.0.9) lib/action_controller/metal/responder.rb:190:in `default_render'
actionpack (3.0.9) lib/action_controller/metal/responder.rb:126:in `to_html'
actionpack (3.0.9) lib/action_controller/metal/responder.rb:119:in `respond'
actionpack (3.0.9) lib/action_controller/metal/responder.rb:112:in `call'
actionpack (3.0.9) lib/action_controller/metal/mime_responds.rb:232:in `respond_with'
devise (1.4.2) lib/devise/controllers/internal_helpers.rb:142:in `respond_with_navigational'
devise (1.4.2) app/controllers/devise/sessions_controller.rb:9:in `new'
actionpack (3.0.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.9) lib/active_support/callbacks.rb:451:in `_run__266949910__process_action__1020298917__callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.9) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.9) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.9) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.9) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.9) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.9) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.9) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.9) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:27:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/mapper.rb:39:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:68:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.9) lib/action_dispatch/routing/route_set.rb:493:in `call'
warden (1.0.4) lib/warden/manager.rb:35:in `block in call'
warden (1.0.4) lib/warden/manager.rb:34:in `catch'
warden (1.0.4) lib/warden/manager.rb:34:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.9) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/home/user1/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/user1/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/user1/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
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 DELETE /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"}
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", :controller=>"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"}
答案 0 :(得分:2)
您是否尝试使用命名路由?替换application.html.erb中的以下行
<div id="header">
<h1>
<%= link_to 'Home', posts_path %>
<%= link_to 'Add Post', new_post_path %>
<%= link_to 'Add Category', new_category_path %>
<%= link_to 'Display Categories', categories_path %>
</h1>
</div>