LoginSignup
0
2

More than 3 years have passed since last update.

【Ruby on Rails】 コントローラー 色々

Last updated at Posted at 2019-04-30

目次

  • 指定したアクションやビューに遷移する(redirect_to)
  • コントローラーのアクションが実行される前に〇〇を実行する(before_action)

指定したビューに遷移する(redirect_to)

redirect_toメソッドをアクション内で利用すると、そこからさらに別のアクションを実行したり、ビューに遷移させたりできます。

controller
redirect_to :action => "index"

コントローラーのアクションが実行される前に〇〇を実行する(before_action)

before_action:メソッド名 と記述することでコントローラのアクションが実行される前に「before_actionで指定したメソッド」を実行することができます。
【オプションなし】

before_action :実行前メソッド名 

【onlyオプション】
〇〇に限り。

before_action :実行前メソッド名, only: 

【exceptオプション】
〇〇以外の場合は。

before_action :メソッド名, except: :メソッド名
0
2
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
2