0
1

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 5 years have passed since last update.

renderメソッド

0
Last updated at Posted at 2019-12-31

renderメソッドを用いる事で別のアクションを経由せずに表示する事が出来る。
似た様な内容でredirect_toメソッドは表示されるアクション内の@変数を利用して表示されるが、renderメソッドはそのアクション内で定義されている@変数を使用してビューを表示する。

例なのでアクション名などは適当です


 def index
   @post = モデル.find_by(引数)
  
 end

 def show
   @post = モデル.find_by(引数)
   @post.カラム名 = params.カラム名
   redirect_to("indexのURL")
 end 

 def update
   @post = モデル.find_by(引数)
   @post.カラム名 = params.カラム名
   render("フォルダ名/ファイル名")
 end

この場合showとupdateはカラム名の中身が変更されたらアクション内では変更されますが、
showの方ではredirect_toで指定してる為、表示されるのはindex内のアクション内容になってしまいます。

このような違いがあります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?