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 RubyonRails教程,由M.Hartl编写。第十章失败测试_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails RubyonRails教程,由M.Hartl编写。第十章失败测试

Ruby on rails RubyonRails教程,由M.Hartl编写。第十章失败测试,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,嗨,我是Hartl的新手。我被困在第十章的微操上了。当我跑的时候 bundle exec rspec spec/requests/authentication_pages_spec.rb 终端返回以下失败消息: Failures: 1) authentication authorization in the Users controller submitting to the update action Failure/Error: before { put user_path(user

嗨,我是Hartl的新手。我被困在第十章的微操上了。当我跑的时候

bundle exec rspec spec/requests/authentication_pages_spec.rb
终端返回以下失败消息:

Failures:

1) authentication authorization in the Users controller submitting to the update action 
 Failure/Error: before { put user_path(user) }
 AbstractController::ActionNotFound:
   The action 'update' could not be found for UsersController
 # ./spec/requests/authentication_pages_spec.rb:78:in `block (5 levels) in <top (required)>'

2) authentication authorization in the Users controller as wrong user submitting a PUT request to the Users#update action 
 Failure/Error: before { put user_path(wrong_user) }
 AbstractController::ActionNotFound:
   The action 'update' could not be found for UsersController
 # ./spec/requests/authentication_pages_spec.rb:110:in `block (6 levels) in <top (required)>'

3) authentication authorization in the Users controller as non-admin user submitting a DELETE request to the Users#destroy action 
 Failure/Error: before { delete user_path(user) }
 AbstractController::ActionNotFound:
   The action 'destroy' could not be found for UsersController
 # ./spec/requests/authentication_pages_spec.rb:122:in `block (6 levels) in <top (required)>'

Finished in 1.54 seconds
21 examples, 3 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:79 # authentication authorization in the Users controller submitting to the update action 
rspec ./spec/requests/authentication_pages_spec.rb:111 # authentication authorization in the Users controller as wrong user submitting a PUT request to the Users#update action 
rspec ./spec/requests/authentication_pages_spec.rb:123 # authentication authorization in the Users controller as non-admin user submitting a DELETE request to the Users#destroy action 

我不确定这是什么原因造成的。有什么想法吗?谢谢Simon

您是否在user\u controller.rb中定义了更新和销毁操作

这是我的参考

class UsersController < ApplicationController
  before_filter :signed_in_user,  only: [:index, :edit, :update]
  before_filter :correct_user,    only: [:edit, :update]
  before_filter :admin_user,      only: :destroy

  def index
    @users = User.paginate(page: params[:page])
  end

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(params[:user])
      sign_in @user
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end

  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User destroyed"
    redirect_to users_path
  end

  private
    def signed_in_user
      unless signed_in?
        store_location
        redirect_to signin_path, notice: "Please sign in"
      end
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to root_path unless current_user?(@user)
    end

    def admin_user
      redirect_to root_path unless current_user.admin?
    end
end
class UsersController
您是否在user\u controller.rb中定义了更新和销毁操作

这是我的参考

class UsersController < ApplicationController
  before_filter :signed_in_user,  only: [:index, :edit, :update]
  before_filter :correct_user,    only: [:edit, :update]
  before_filter :admin_user,      only: :destroy

  def index
    @users = User.paginate(page: params[:page])
  end

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(params[:user])
      sign_in @user
      flash[:success] = "Profile updated"
      redirect_to @user
    else
      render 'edit'
    end
  end

  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "User destroyed"
    redirect_to users_path
  end

  private
    def signed_in_user
      unless signed_in?
        store_location
        redirect_to signin_path, notice: "Please sign in"
      end
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to root_path unless current_user?(@user)
    end

    def admin_user
      redirect_to root_path unless current_user.admin?
    end
end
class UsersController