Rails创建操作在应该呈现新操作时重定向到索引

Mat*_*att 8 rest routing ruby-on-rails

如果我提交有错误的新用户表单,它会重定向到索引页面,然后在其上呈现新页面.在控制器中,我指定它应该只呈现新操作,以便用户可以查看/修复他们的错误并重新提交.有什么明显的东西让我失踪吗?

这是我的控制器代码中的创建操作:

def create
  @user = User.new(params[:user])
  @user.role = "owner"

  if @user.save
    flash[:notice] = "Registration successful!"
  else
    flash.now[:notice] = "You have errors!"
    render :new
  end
end
Run Code Online (Sandbox Code Playgroud)

Lad*_*ein 0

我想你想说

redirect_to :action => 'new'
Run Code Online (Sandbox Code Playgroud)