0

こんにちは私は最近railscast#270(Rails 3.1での認証)を見ました。私は3.2RailsATMを実行しています。アプリケーションにサインアップすると、すべてが機能しているように見えますが、まったく同じユーザー名とパスワードでサインインしようとすると、拒否されます。コードは以下のとおりです。

# == Schema Information
#
# Table name: users
#
#  id              :integer          not null, primary key
#  username        :string(255)
#  password_digest :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

User.rb

    class User < ActiveRecord::Base
  attr_accessible :username, :password, :password_confirmation

  # validations

  has_secure_password

  end

SessionsHelper.rb

module SessionsHelper
    def signed_in?
    !current_user.nil?
  end
end

ApplicationHelper.rb

module ApplicationHelper
    def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
end

users_controller.rb

class UsersController < ApplicationController
  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
        redirect_to root_path, :flash => { :success => "Signed Up!" }
    else
        render :new
    end
  end
end

session_controller.rb

class SessionsController < ApplicationController
  def new
  end

  def create
    user = User.find_by_username(params[:username])
    if user and user.authenticate(params[:password])
        session[:user_id] = user.id
        redirect_to root_path, :flash => { :success => "Signed In! " }
    else
        flash.now[:error] = 'Invalid email/password combination'
        render :new
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_path, :flash => { :success => "Signed Out!" }
  end
end

フォームは基本的なフォームであり、エラーメッセージが部分的に含まれているため、問題が発生した場合にフラッシュメッセージが表示されます。コードや情報を載せていない場合はお知らせください。前もって感謝します :)

更新-Railsサーバーログ(私が見つけることができるのはログのみ)

Rendered /usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)


Started GET "/assets/pages.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /pages.js - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /jquery.js - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /custom.css - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /jquery_ujs.js - 304 Not Modified (9ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /sessions.js - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /application.js - 304 Not Modified (4ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/bootstrap" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /bootstrap - 404 Not Found (4ms)

ActionController::RoutingError (No route matches [GET] "/assets/bootstrap"):
  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)


Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /users.js - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/blueprint/print.css?body=1" for 127.0.0.1 at 2013-01-24 17:18:48 +1100
Served asset /blueprint/print.css - 304 Not Modified (0ms)
[2013-01-24 17:18:48] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
4

0 に答える 0