0

我在routes.rb文件中有这个设计路线:

 app::Application.routes.draw do
 scope ":locale", locale: /#{I18n.available_locales.join("|")}/  do
         devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" } do
         delete "/logout" => "devise/sessions#destroy"
         get "/login" => "devise/sessions#new"
         get "/sign_up" => "devise/registrations#new"
         get "/settings" => "devise/registrations#edit"
         get "/recover_password" =>  "devise/passwords#new"
         get "/confirm_account" =>  "devise/confirmations#new"
        end
      end
   match '*path', to: redirect("/#{I18n.default_locale}/%{path}")
   match '', to: redirect("/#{I18n.default_locale}")
 end

我在项目中使用http://localhost:3000/es西班牙语和http://localhost:3000/en英语。

如果我去http://localhost:3000/en/sign_up并尝试创建一个新用户并失败,则重定向到http://localhost:3000/en/users

这种重定向是错误的,因为如果我尝试在我的切换语言中更改语言,我会在浏览器中重定向到 users#index 操作。

我需要重定向转到http://localhost:3000/en/sign_uphttp://localhost:3000/es/sign_up

我已经覆盖了在registrations_controller.rb创建的设计操作

class RegistrationsController < Devise::RegistrationsController

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with({}, :location => after_sign_up_fails_path_for(resource))
    end
  end

  private
  def after_sign_up_fails_path_for(resource)
   sign_up_path
  end

end

这里的问题是我看不到字段形式的错误。我的意思是该应用程序不会在表单字段中显示错误。devise_error_messages 为空。

我该如何解决这个问题?

非常感谢

4

1 回答 1

2

(我的回答错了——我改了)

我认为不是在失败时重定向:

respond_with({}, :location => after_sign_up_fails_path_for(resource))

您希望使用相同的失败资源留在同一页面上:

render :action => 'new'

尽管原行应该具有相同的效果:

respond_with resource
于 2012-04-22T14:16:29.663 回答