Rails创建动作应在应呈现新动作时重定向到索引 [英] Rails create action is redirecting to index when it should be rendering the new action

查看:77
本文介绍了Rails创建动作应在应呈现新动作时重定向到索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我提交有错误的新用户表单,它将重定向到索引页面,然后在其顶部呈现新页面。在控制器中,我指定应仅呈现新操作,以便用户可以查看/修复其错误并重新提交。

If I submit a new user form with errors, it redirects to the index page and then renders the new page on top of it. In the controller I specify that it should just render the new action so that the user can see/fix their errors and resubmit. Is there something obvious that I am missing?

这是我的控制器代码中的create动作:

Here's the create action in my controller code:

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'

这篇关于Rails创建动作应在应呈现新动作时重定向到索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆