我用我的用戶模型安裝了正常的Devise安裝。註冊並註銷工作正常,但表單中的登錄只是重定向回登錄頁面。設計登錄未完成
我已經把幾乎所有的默認:
會議/ 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 "https://stackoverflow.com/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"=>"[email protected]", "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"=>"[email protected]", "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 "https://stackoverflow.com/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"=>"[email protected]", "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
我在原來的答案中添加了一個編輯。你的文章給了我一個主意。 – 2013-02-15 01:30:12