无法为UsersController找到“创建”操作

时间:2020-12-30 01:17:04

I am doing Chapter 7 of Michael Hartl's Rails tutorial, and I am getting errors when trying to sign up a user in development. I have finished the chapter through 7.3 so all of my tests should be passing now, but I'm still receiving The action 'create' could not be found for UsersController in development.

我正在做Michael Hartl的Rails教程的第7章,我在尝试在开发中注册用户时遇到错误。我已经完成了7.3的章节,所以我的所有测试都应该现在通过,但我仍然收到了在开发中找不到用户控件的动作'create'。

Here is my Users Controller

这是我的用户控制器

class UsersController < ApplicationController

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

  def new
    @user = User.new

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

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end
    end     
end

At this point in the tutorial I should be able to sign a user up in the online form without issue. Here is my github repository https://github.com/ajhausdorf/sample_app

在本教程的这一点上,我应该能够在线表单中注册用户而不会出现问题。这是我的github存储库https://github.com/ajhausdorf/sample_app

4 个解决方案

#1


6  

Your def new has not been closed.

您的def new尚未关闭。

This code should works

这段代码应该有效

class UsersController < ApplicationController

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

  def new
    @user = User.new
  end # Here what you missing

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

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end

end

#2


3  

Your ends are out of whack:

你的目标是不正常的:

class UsersController < ApplicationController

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

  def new
    @user = User.new
  end # You were missing one here.

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

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end
    # end # You have an extra one here.
end

#3


3  

Your new method doesn't end where you think it ends; it encompasses both the create and user_params methods.

你的新方法不会在你认为结束的地方结束;它包含create和user_params方法。

You've created a local method called create inside the new method, rather than creating a regular instance method called create on the UserController class.

您已在新方法中创建了一个名为create的本地方法,而不是在UserController类上创建一个名为create的常规实例方法。

#4


0  

def new
  @user = User.new
end  # you are missing this line

def create

#1


6  

Your def new has not been closed.

您的def new尚未关闭。

This code should works

这段代码应该有效

class UsersController < ApplicationController

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

  def new
    @user = User.new
  end # Here what you missing

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

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end

end

#2


3  

Your ends are out of whack:

你的目标是不正常的:

class UsersController < ApplicationController

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

  def new
    @user = User.new
  end # You were missing one here.

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

    def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end
    # end # You have an extra one here.
end

#3


3  

Your new method doesn't end where you think it ends; it encompasses both the create and user_params methods.

你的新方法不会在你认为结束的地方结束;它包含create和user_params方法。

You've created a local method called create inside the new method, rather than creating a regular instance method called create on the UserController class.

您已在新方法中创建了一个名为create的本地方法,而不是在UserController类上创建一个名为create的常规实例方法。

#4


0  

def new
  @user = User.new
end  # you are missing this line

def create