2012-12-10 23 views
0

我想爲我的用戶子類 - 成員和合作夥伴設置2個略有不同的註冊過程。我想讓它這樣:單獨的註冊過程用戶的子類兒童

/用戶/ sign_up簽約用戶爲會員(所以我有一個隱藏字段中存在與價值「會員」),它就像一個魅力。

但我也想:

/用戶/合作伙伴/ sign_up提供一個稍微不同的形式歸咎於他們的價值「合作伙伴」。

我特別希望這2個不同的網址實現的,這樣我就可以把這些不同類型的用戶提供不同的鏈接與註冊。

我使用的設計我的身份驗證系統。

我敢肯定,我應該產生一個獨立的控制器,如partner_registrations_controller的東西,並從色器件繼承,但我不知道是什麼代碼應該然後去控制器。

我也覺得我需要創建的意見/用戶文件夾,在那裏我將有特定的「new.html.erb」形式中的一個新文件夾「partner_registrations」。

我終於我知道我需要做一些與途徑,如:

devise_for :users, :controllers => { :registrations => :registrations } do 
     get 'users/partner/sign_up', to: 'devise/registrations#new' 
    end 

我讀過GitHub上此維基頁面:https://github.com/plataformatec/devise/wiki/How-To:-Customize-routes-to-user-registration-pages但我不爲它的聰明。

任何幫助,非常感謝。

回答

0

我想通了,所以以爲我會發布的情況下,回答其他人發現它在未來有用:

路線文件:

devise_scope :user do 
    get 'sign_up', to: 'members#new', controller: {registrations: "members"} 
    get 'partners/sign_up', to: 'content_partners#new', controller: {registrations: "content_partners"} 
    end 
    devise_for :users, controllers: {registrations: :registrations} 

我創建2級獨立的控制器爲每個孩子類,與由色器件給予基本相同的新創建行動:

class MembersController < Devise::RegistrationsController 
    def new 
    resource = build_resource({}) 
    respond_with resource 
    end 

    # POST /resource 
    def create 
    build_resource 

    if resource.save 
     if resource.active_for_authentication? 
     set_flash_message :notice, :signed_up if is_navigational_format? 
     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}" 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 resource 
    end 
    end 
end 

我剛剛更換「會員」在控制器的其他子類的ContentPartners「。

然後我創建的意見/ Users文件夾2個新的文件夾 - 注意這讓我的疑難雜症,他們必須得使用複數 - 如此/成員和/ content_partners。然後在每個文件夾中創建一個獨特的'new.html.erb'文件。

就是這樣。