如果我提交一个有错误的新用户表单,它会重定向到索引页面,然后在它上面呈现新页面。在 Controller 中,我指定它应该只呈现新操作,以便用户可以查看/修复他们的错误并重新提交。有什么明显的我遗漏了吗?
这是我的 Controller 代码中的创建操作:
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
最佳答案
我想你想说
redirect_to :action => 'new'
关于ruby-on-rails - Rails 创建操作在应该呈现新操作时重定向到索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3937638/