【问题标题】:Changing devise user_registration_path更改设计 user_registration_path
【发布时间】:2013-10-29 10:38:44
【问题描述】:

来自我的rake routes

     user_registration POST   /users(.:format)               devise/registrations#create
 new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new

所以当我点击注册表单中的提交按钮时,它会将我移动到/users

我怎样才能将它更改为 user_registration POST 将是 /users/sign_up(.:format) ? 我试过这样的事情:

  devise_for :users

  as :user do
    post 'sign_up' => 'devise/registrations#create', as: 'user_registration'
  end

但是由于user_registration前缀已经由devise_for生成,所以存在冲突

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

    要执行您想要的操作,您需要停止生成默认注册#create 操作。不幸的是,没有简单的方法可以做到这一点(或定制它)。我能找到的最好方法是跳过为用户生成注册路由,稍后使用 devise_scope 方法定义所有这些路由:

    devise_for :users, skip: :registration
    devise_scope :user do
      resource :registration, :as => :user_registration, :only => [ :new, :edit, :update, :destroy ], :path=> "/users", :path_names=> { :new =>"sign_up" }, :controller=>"devise/registrations"  do
        get :cancel
        post :sign_up, action: :create, as: ''
      end
    end
    

    这可能会被清理一下,但它会产生你所期望的:

        user_registration POST   /users/sign_up(.:format)       devise/registrations#create
    new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
    

    附:相关问题在this thread讨论

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 2012-06-20
      相关资源
      最近更新 更多