LoginSignup
0
1

More than 3 years have passed since last update.

redirect_toで思いどおりのページへ ❏Rails❏

Last updated at Posted at 2019-11-17

redirect_to "ページ先"

これだけで好きなページへ遷移させることができます。
指定方法は以下。

URLで指定

xxx_controller.rb
redirect_to "http://www.manbow.com"


prefixで指定

xxx_controller.rb
redirect_to root_path


アクションで指定

xxx_controller.rb
redirect_to action: :new


指定したコントローラーのアクションで指定

xxx_controller.rb
redirect_to controller: :users, action: :show


個別のリソースを指定

xxx_controller.rb
redirect_to controller: :users, action: :show, id: 1


前のページを指定

xxx_controller.rb
redirect_to :back





僕は基本prefixを使っています。



ではまた!

0
1
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
1