我使用我的用户模型进行了正常的设计安装。注册和注销工作正常,但登录表单只是重定向回登录页面。
我几乎将所有内容都保留为默认值:
会话/new.html.erb
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => user_session_path) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div><br/>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div><br/>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
users_controller.rb
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end
# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @user }
end
end
# GET /users/new
# GET /users/new.json
def new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @user }
end
end
# GET /users/1/edit
def edit
@user = User.find(params[:id])
end
# POST /users
# POST /users.json
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])
if params[:user][:password].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end
end
路线
devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}
resources :users
以下是尝试登录后创建的日志。
Started POST "/users/login" for 127.0.0.1 at 2013-02-13 19:18:34 -0600
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"oPVQIraxxQ3m8I4hbqy0r/BLIUaESkNDLFhvtoRIf2Q=", "user"=>{"email"=>"MYEMAIL@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 1ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"oPVQIraxxQ3m8I4hbqy0r/BLIUaESkNDLFhvtoRIf2Q=", "user"=>{"email"=>"MYEMAIL@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/_links.erb (0.5ms)
Rendered devise/sessions/new.html.erb within layouts/application (5.5ms)
Completed 200 OK in 108ms (Views: 29.8ms | ActiveRecord: 0.0ms | Solr: 0.0ms)
我尝试将更改添加form_for
到以下内容:
<%= form_for(resource, :as => resource_name, :url => user_session_path(resource_name)) do |f| %>
但这http://localhost:3000/users/login.user
让我在开发日志中得到了这个:
Started POST "/users/login.user" for 127.0.0.1 at 2013-02-13 19:21:36 -0600
Processing by Devise::SessionsController#create as
Parameters: {"utf8"=>"✓", "authenticity_token"=>"oPVQIraxxQ3m8I4hbqy0r/BLIUaESkNDLFhvtoRIf2Q=", "user"=>{"email"=>"demeuseja@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 1ms
我确定这是一个错误的输入或我忽略的东西,因为除了登录之外一切正常,但我已经修改了几个小时并且不知道问题是什么。任何正确方向的观点将不胜感激!
谢谢!
编辑
这也是我的用户模型:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :bio, :employer, :looking, :name, :password, :statement, :user_id, :username
validates :name, :presence => true, :length => { :minimum => 3 }
has_many :venues
scope :employer, where(employer:true)
scope :looking, where(looking:true)
scope :recent, order("created_at_desc").limit(3)
end