LoginSignup
0
0

More than 5 years have passed since last update.

redirect_toする前に特定のメソッドを実行したい場合の注意

Last updated at Posted at 2019-04-26

■ 駄目な例

以下の書き方だと、private_methodが実行される前にredirect_toが実行される。

controllers/users_controller.rb
  def send_report
    private_method
    redirect_to action: :index
  end

  private

  def private_method
  end

■ 良い例

以下の書き方だとprivate_methodが実行されてからredirect_toが実行される。

controllers/users_controller.rb
  def send_report
    redirect_to action: :index if private_method
  end

  private

  def private_method
  end



ご参考になりましたら幸いです。


.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0