Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.2身份验证返回无效的用户名/密码组合_Ruby On Rails_Ruby_Security_Authentication_Login - Fatal编程技术网

Ruby on rails Rails 3.2身份验证返回无效的用户名/密码组合

Ruby on rails Rails 3.2身份验证返回无效的用户名/密码组合,ruby-on-rails,ruby,security,authentication,login,Ruby On Rails,Ruby,Security,Authentication,Login,嗨,我最近看了railscast#270(Rails 3.1中的身份验证)。我正在运行3.2 Rails atm。当我注册应用程序时,一切似乎都正常,但当我尝试使用完全相同的用户名和密码登录时,我被拒绝了。代码如下: # == Schema Information # # Table name: users # # id :integer not null, primary key # username :string(255) #

嗨,我最近看了railscast#270(Rails 3.1中的身份验证)。我正在运行3.2 Rails atm。当我注册应用程序时,一切似乎都正常,但当我尝试使用完全相同的用户名和密码登录时,我被拒绝了。代码如下:

# == 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
ApplicationHelper.rb

module ApplicationHelper
    def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
end
用户\u 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
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服务器日志进行了更新,这是我唯一能找到的日志My specs return-Failure/error:controller.What_signed_in expected signed_in?要返回true,则得到false 1。从您的日志中,我没有看到任何ruby失败,但是css失败(与引导相关的问题)2。如果您想在rspec中使用登录功能,请使用其官方文档提供的
模拟登录方法
。在开发或生产环境中运行时,这并不能解决我的问题
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
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