2012-07-09 3 views
0

그래서, 내가 새로 등록 된 사용자재정 유증 등록 # 추가 할 어떤 청소기 방법이 있나요

class RegistrationsController < Devise::RegistrationsController 
    def create 
    build_resource 
    resource.role = Role.find_by_name('registered') 
    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 resource 
    end 
    end 
end 

에 대한 역할 할당을 추가 내 앱에서 내 자신의 등록 컨트롤러가 논리를 복사/붙여 넣기없이 만들 이 방법에 기능? 내가 devise의 코드를 복사 할 필요가 없다는 것을/자신의 논리를 광산과 분리되도록 내 방법에 붙여 넣는 것을 선호합니다.

은 내가 콜백으로, 모델 수준에서 그것을 처리 할 수 ​​있다고 생각하지만, 나는 가장 좋은 방법

+0

스키니 컨트롤러, 뚱뚱한 모델. – janders223

답변

0

그냥 콜백

class User < ActiveRecord::Base 
    before_create :set_role 

    private 
    def set_role 
    if self.role.nil? 
     self.role = Role.find_by_name('registered') 
    end 
    end 
end 

많은 청소기이 리팩토링까지 종료 모르겠어요 . 고객의 컨트롤러를 모두 제거했습니다.

관련 문제