我收到这个错误,这让我感到困扰.我不知道发生了什么......我已按照T的说明进行操作,但仍在抱怨 - 请帮助!我有错误消息,控制器文件,登录页面和路由文件的摘录.
错误信息NoMethodError in User_sessions#new
Showing app/views/user_sessions/new.html.erb where line #4 raised:
undefined method `user_sessions_path' for #
提取的来源(第4行):
应用程序/视图/用户/ login.rhtml4. <% form_for @user_session do |f| %>
5. <%= f.error_messages %>
控制器/ user_sessions_controller.rb
class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_to root_url
#redirect_back_or_default account_url
else
render :action => :new
end
end
def destroy
current_user_session.destroy
flash[:notice] = "Logout successful!"
redirect_to root_url
#redirect_back_or_default account_url
end
end
user_sessions/new.html.erb
#User Login
<% form_for @user_session do |f| %>
<%= f.error_messages %>
<%= f.label :Email %>
<%= f.text_field :email %>
<%= f.label :Password %>
<%= f.password_field :password %>
<%= f.submit "Submit" %>
<% end %>
routes.rb文件
ActionController::Routing::Routes.draw do |map|
map.login "login", :controller => "user_sessions", :action => "new"
我在错误的地方看?
问题是你的路线文件.你不是在休息.所以<%form_for @user_session%>
不会知道如何创建网址.
添加map.resource: user_session
到routes.rb应该可以解决您的问题.
您应该阅读restful_authentication插件的文档.