2013-06-01 2 views
0

Device의 guide을 사용하여 사용자가 암호없이 계정을 만들 수 있지만 확인시 나중에 설정하는 기능을 설정하고 있습니다.변경 오류로 인한 플래시 오류 변경

그러나 오류는 <%= devise_error_messages! %>에서 발췌되었습니다. 컨트롤러를 변경하고 싶습니다. 레일스의 일반적인 flash에 표시됩니다.

어떻게하면됩니까?

내가 무시하고있어 컨트롤러는 다음과 같다 :

# app/controllers/confirmations_controller.rb 
class ConfirmationsController < Devise::ConfirmationsController 

    layout "login" 

    # Remove the first skip_before_filter (:require_no_authentication) if you 
    # don't want to enable logged users to access the confirmation page. 
    skip_before_filter :require_no_authentication 
    skip_before_filter :authenticate_user! 

    # PUT /resource/confirmation 
    def update 
    with_unconfirmed_confirmable do 
     if @confirmable.has_no_password? 
     @confirmable.attempt_set_password(params[:user]) 
     if @confirmable.valid? 
      do_confirm 
     else 
      do_show 
      @confirmable.errors.clear #so that we wont render :new 
     end 
     else 
     self.class.add_error_on(self, :email, :password_allready_set) 
     end 
    end 

    if [email protected]? 
     render 'devise/confirmations/new' #Change this if you don't have the views on default path 
    end 
    end 

    # GET /resource/confirmation?confirmation_token=abcdef 
    def show 
    with_unconfirmed_confirmable do 
     if @confirmable.has_no_password? 
     do_show 
     else 
     do_confirm 
     end 
    end 
    if [email protected]? 
     self.resource = @confirmable 
     render 'devise/confirmations/new' #Change this if you don't have the views on default path 
    end 
    end 

    protected 

    def with_unconfirmed_confirmable 
    @confirmable = User.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token]) 
    if [email protected]_record? 
     @confirmable.only_if_unconfirmed {yield} 
    end 
    end 

    def do_show 
    @confirmation_token = params[:confirmation_token] 
    @requires_password = true 
    self.resource = @confirmable 
    render 'devise/confirmations/show' #Change this if you don't have the views on default path 
    end 

    def do_confirm 
    @confirmable.confirm! 
    set_flash_message :notice, :confirmed 
    sign_in_and_redirect(resource_name, @confirmable) 
    end 
end 

답변

2

난 당신이 오류 메시지와 혼합 플래시 메시지가있을 수 있습니다 생각합니다. <%= devise_error_messages! %>을 통해 오류가 표시되면 해당 오류 메시지가 모델에 설정된 유효성 검사에서 비롯된 것입니다. User 모델의 예를 들면,

validates :password, presence: true 

를 들어이 플래시 메시지에 비해 다른 오류가 있습니다. 당신은이 플래시 메시지는 당신이 컨트롤러 액션에서 지정한 조건에 반응이

def create 
    # code ..... 
    if @post.save 
    flash[:success] = "Post was successfully created" 
    redirect_to [@investigation, @post] 
    else 
    flash.now[:error] = "Post was not created" 
    render 'new' 
    end 
end 

같은 컨트롤러에 flash 메시지를 설정합니다. 희망이 도움이