我的 layouts/application.html.erb 上有一个表单,它贴在下面,如果我添加该行<%= devise_error_messages! %>
,我会收到下面的错误。
如何在没有分页符的情况下添加 devise_error_messages?
/app/views/layouts/application.html.erb
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %> <!-- this line causes issues -->
<h3>Add new contact</h3>
First Name<br />
<%= f.text_field :username %><br />
Last Name<br />
<%= f.text_field :password %><br />
<%= f.text_field :password_confirmation %><br />
Email<br />
<%= f.text_field :email %>
<hr />
<%= f.submit "Add Contact" %>
<% end %>
错误:
NoMethodError in My_devise/sessions#index
Showing /app/views/layouts/application.html.erb where line #59 raised:
undefined method `errors' for nil:NilClass
Extracted source (around line #59):
56: <a href="#" class="has-popupballoon button button-blue"><span class="add"></span>New Contact</a>
57: <div class="popupballoon top">
58: <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
59: <%= devise_error_messages! %>
60: <h3>Add new contact</h3>
61: First Name<br />
62: <%= f.text_field :username %><br />
这是我正在使用的网址http://localhost:3000/admin/home
,这是我的 routes.rb
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
get "/users/sign_in", :to => "my_devise/sessions#new"
get 'admin/home', :to => 'my_devise/sessions#index'
get 'users/sign_up', :to => 'my_devise/registrations#new'
end
devise_for :users, :controllers => {:sessions => "my_devise/sessions", :registrations => "my_devise/registrations"}
get "home/index"
root :to => "home#index"
/app/controllers/my_devise/sessions_controller.rb
class MyDevise::SessionsController < Devise::SessionsController
layout false
before_filter :authenticate_user!
def index
render :layout => 'application'
end
def new
super
end
def create
super
end
end
/app/controllers/my_devise/registrations_controller.rb
class MyDevise::RegistrationsController < Devise::RegistrationsController
def index
end
end
耙路线:
users_sign_out GET /users/sign_out(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
users_sign_in GET /users/sign_in(.:format) {:controller=>"my_devise/sessions", :action=>"new"}
admin_home GET /admin/home(.:format) {:controller=>"my_devise/sessions", :action=>"index"}
users_sign_up GET /users/sign_up(.:format) {:controller=>"my_devise/registrations", :action=>"new"}
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"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"my_devise/sessions"}
POST /users/sign_in(.:format) {:action=>"create", :controller=>"my_devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"my_devise/sessions"}
POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
GET /users/cancel(.:format) {:action=>"cancel", :controller=>"my_devise/registrations"}
POST /users(.:format) {:action=>"create", :controller=>"my_devise/registrations"}
GET /users/sign_up(.:format) {:action=>"new", :controller=>"my_devise/registrations"}
GET /users/edit(.:format) {:action=>"edit", :controller=>"my_devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"my_devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"my_devise/registrations"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}