2017-05-03 8 views
0

別のプライベートメソッドを呼び出すアクションを書きました 特定の条件が満たされている場合は別のページにリダイレクトするか、実行を続行します。 しかし私はできませんでした 私はredirect_to root_pathダブルレンダリングを使用しようとしたとき 実際にプライベートメソッドからレンダリングの代わりに実際に呼び出されたアクションステートメントを実行しようとしています。redirect_toが実行された後に実行を停止する方法

def actual_method_called 
    data1 = params[:data1] 
    method_2(data1) 
    data2 = params[:data1] 
    method_2(data2) 
    render json: {status: 'ok' } 
end 

private 

def method_2(data) 
    if data.valid? 
    puts 'continue the execution' 
    else 
    redirect_to root_path and return 
    end 
end 
あなたが呼び出されるメソッドから値を返すことができ
+0

あなたはRailsの上で何のRubyのバージョンを使用しています? –

+0

Rails 5.0.0.1 version ruby​​ 2.2.5p319 – chinna2580

+0

'before_action'フィルタに' method_2'を入れることができます。 –

答えて

0

...

def method_2(data) 
    if data.valid? 
    puts 'continue the execution' 
    return 
    else 
    redirect_to root_path 
    return :redirected 
    end 
end 

温家宝首相は、あなたが戻り値を格納し、それを呼び出す

def actual_method_called 
    data1 = params[:data1] 
    return_status ||= method_2(data1) 
    data2 = params[:data1] 
    return_status ||= method_2(data2) 
    render json: {status: 'ok' } unless return_status == :redirected 
end 
関連する問題