Rails create action is redirecting to index when it should be rendering the new action

一曲冷凌霜 提交于 2019-12-10 03:03:52

问题


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?

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

回答1:


I think you want to say

redirect_to :action => 'new'


来源:https://stackoverflow.com/questions/3937638/rails-create-action-is-redirecting-to-index-when-it-should-be-rendering-the-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!