更改注册controller创建动作故障重定向路径



我正在尝试在我的应用程序的主页上实现注册表格。成功的流(注册(效果很好。问题在于当验证失败时,即触发设计注册的启用者:新操作。我希望这种果兰代者在主页上发生而不是设计自己的视图。

我试图通过将root_path位置添加到" rection_with位置"来重写设计控制器,但是由于某种原因,这继续触发渲染的设计视图。

  # POST /resource
  def create
    build_resource(sign_up_params)
    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource, location: root_path # HERE!!!
    end
  end

我想知道解决此问题的干净方法

编辑

让我感到惊讶的是,我可以使用首选的模板渲染主场布局,但是这感觉有些不当。

  # POST /resource
  def create
    build_resource(sign_up_params)
    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      render layout: 'frontend/home', template: 'frontend/home/index'
    end
  end

我最终与上面的编辑一起使用了该方法:

  render layout: 'frontend/home', template: 'frontend/home/index'

最新更新