在Spree Rails中验证失败时,地址栏URL已更改

时间:2014-03-15 17:08:19

标签: ruby-on-rails ruby-on-rails-4 routes spree

我刚刚覆盖views/spree/user_registations/new.html.erb并在此文件中添加了我的内容。

当我点击localhost:3000/时,我会收到自定义表单。

在验证失败的情况下,它会呈现操作'new'

接下来,在验证失败后,'new'操作部分将被呈现并且&我明白了。

但是在浏览器地址中,我得到了" http://localhost:3000/spree/signup"。

我希望它只是localhost:3000/

我们如何实现这一点,并且在验证失败时仅在地址栏中查看localhost:3000/

#routes.rb : 
  root to: 'spree/user_registrations#new', as: '/'

这是我的观看部分:

#spree/user_registrations/new.html.erb 

<%= form_for @user,  url:  spree.registration_path(@user),  id: 'user_new'   do |f| %> 

<span> <%= f.text_field :email, :placeholder => "Email *", name: 'email' %>
<span> <%= f.password_field :password, name: 'password' %></span>
<span> <%= f.password_field :password_confirmation name: 'password_confirmation' %></span>

<% end %>

控制器:

    Spree::UserRegistrationsController.class_eval do
        def new
        @user = Spree::User.new
        end

       def create
             @user = Spree::User.new(email: params[:email], password: params[:password], password_confirmation: params[:password_confirmation])

                    if @user.save
                        session[:customer_id] = @user.id
                        set_current_user(@user.id)
                        redirect_to main_app.profile_dashboards_path  and return
                    else
                        render 'new'
                    end
                end
        end

end

0 个答案:

没有答案