This is a post to output "Ruby on Rails 5 Quick Learning Practice Guide" in Continued from last time. This time, I will tell you how to display a Flash message when transitioning pages!
<!-Edit title and anchor name->
<!-Each chapter-> redirect_to Write redirect_to as follows.
redirect_to pass, notice: "#{name}Registered"
Other than notice, you can also pass alert by default.
redirect_to pass, alert: "Registration failed"
render In the case of render, the description is as follows.
flash.now[:alert] = "Please enter a name."
render :new
Describe and display as follows in the transition destination template.
- if flash.notice.present?
= flash.notice
If you expect all Flash to be displayed at the top of the page, it will be refreshing to write this in application.html.slim!
-Ruby on Rails 5 Quick Learning Practice Guide that can be used in the field
Recommended Posts