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

メッセージが投稿されたときに、一時的に「成功しました」的な表示をさせたい

Posted at

#はじめに
 メッセージが投稿されたときに、ちゃんと投稿できたか、ユーザーに知らせた方が、使い勝手がよい思い、調べた。

##コントローラー側の記述

controllers
def create
  @post = Post.new(post_params)
  if @post.save
    flash[:success] = '送信されました'
    redirect_to root_path
  else
    render :new
  end
end

##ビュー側の記述

views

<%= flash[:success] %>

##最後に
 成功したときだけじゃなく、失敗したときにもメッセージを表示できるようにしよう!

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?