ユーザーモデルで通常の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 "/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