Ruby on rails 设计重定向以对错误进行索引操作

Ruby on rails 设计重定向以对错误进行索引操作,ruby-on-rails,devise,Ruby On Rails,Devise,我正在使用Desive,如果您尝试使用现有电子邮件注册,则会遇到问题 当您注册时,您可以通过以下url进行注册: http://localhost:3000/accounts/new 所以我有一个帐户,在那里我添加了一个用户(Desive)。如果我尝试注册为一个已经存在的用户,我会得到正确的错误: “用户电子邮件已被接收” 但它会重定向到http://localhost:3000/accounts 控制器看起来有点像这样: def create name = account_para

我正在使用Desive,如果您尝试使用现有电子邮件注册,则会遇到问题

当您注册时,您可以通过以下url进行注册:

http://localhost:3000/accounts/new
所以我有一个帐户,在那里我添加了一个用户(Desive)。如果我尝试注册为一个已经存在的用户,我会得到正确的错误:

“用户电子邮件已被接收”

但它会重定向到
http://localhost:3000/accounts

控制器看起来有点像这样:

 def create
    name = account_params[:name]

    first_name =  Modules::NameHelpers.get_first_name(name)
    last_name = Modules::NameHelpers.get_last_name(name)

    @account = Account.new(account_params_wo_user_name)
    @account.users.first.first_name = first_name
    @account.users.first.last_name = last_name

    respond_to do |format|
        if @account.save
            sign_in @account.users.first

            format.html { redirect_to root_path, notice: "Thanks for signing up." }
            format.json { render action: 'show', status: :created, location: @account }
        else
            format.html { render action: 'new' }
            format.json { render json: @account.errors, status: :unprocessable_entity }
        end
    end
end
我似乎找不到什么重定向到索引页

更新: 表格如下:

<%= form_for(@account) do |f| %>
    <%= render 'shared/error_messages', :object => f.object %>

    <div>
      <%= f.label :name, 'Account Name' %> <br />
      <%= f.text_field :name, :required => true, :placeholder => 'Your account name' %>
    </div>

    <%= f.fields_for :users do |user_form| %>
        <div><%= user_form.label :name %><br />
          <%= user_form.text_field :name, :autofocus => true, :required => true, :placeholder => 'Your name' %></div>

        <div><%= user_form.label :email %><br />
          <%= user_form.email_field :email, :required => true, :placeholder => 'Your email' %></div>

        <div><%= user_form.label :password, :required => true %><br />
          <%= user_form.password_field :password, :required => true, :placeholder => 'Enter a 8 character password'%></div>

        <div><%= user_form.label :password_confirmation, :required => true %><br />
          <%= user_form.password_field :password_confirmation, :required => true, :placeholder => 'Confirm password' %></div>
    <% end %>

    <div><%= f.submit "Sign up" %></div>
<% end %>

f、 对象%>

true,:占位符=>'您的帐户名'%>
true,:required=>true,:占位符=>'您的姓名''>
true,:占位符=>'您的电子邮件'%> 正确%>
true,:占位符=>'输入8个字符的密码'%> 正确%>
true,:占位符=>'确认密码'>
你能发布你的日志吗?你提到它指向
/accounts
路径-它仍然显示表单吗?我认为这是一个标准的Railsissue@RichPeck你是对的。我忘了表格。它现在已经被添加了,这不是索引,而是创建URL。到底发生了什么不应该发生的事情?@Dofs您应该更改您的问题标题,这是一个创建url而不是索引。如果您的表单存在验证错误,则应该是这样。有关详细信息,请查阅