0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

renderメソッドとredirect_toの使い方

Last updated at Posted at 2021-03-02

renderメソッド

別のアクションを経由せずに直接ビューを表示できる
使い道は、更新などが失敗した場合、更新内容を保持しておきたい時に使う
renderメソッドを使うと、redirect_toメソッドを使った場合と違い、そのアクション内で定義した@変数をビューでそのまま使うことができる。

render("フォルダ名/ファイル名")
のように表示したいビューを指定する

コントローラー
@fefefe = test
render("ccc/ddd") ビューファイルを指定
-+-+-+-+-+-+-+
ccc/ddd.html.erb
<%= @fefefe =>

renderで書く時は最初の"/"がいらない

####redirect_toメソッド
redirect_toはURLを指定して
redirect_to(URL)
のように書く

コントローラー
redirect_to("/aaa/bbb")

ルーター
get "aaa/bbb" => "aaa#bbb"

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?