My application has two parts. In one part work without layout. In top of the controller has a line layout false. I want to display a flash message in my view when submit my form. but in all flash message tutorials used layout application.html file but in my case i'll not use layout. appreciate your ideas
Asked
Active
Viewed 922 times
0
-
You can use that inside page, which working without layout – fool-dev Jan 05 '18 at 07:59
-
Just copy the code for flash messages from layouts/application.html.erb to the desired view file (the one rendered without layout) – Jagdeep Singh Jan 05 '18 at 09:27
1 Answers
0
You can use that in two ways
One You can use that inside page, which working without layout like
On the top of the page and every page which you need show flash
# page.html.erb
<% flash.each do |msg| %>
<%= msg %>
<% end %>
OR
<% if alert.present? %> # or :notice
<%= alert %>
<% end %>
Two This way is more generic like you can create a folder inside view and named common
inside this create partial
file and named _flash.html.erb
# view/common/_flash.html.erb
<% flash.each do |msg| %>
<%= msg %>
<% end %>
OR
<% if alert.present? %> # or :notice
<%= alert %>
<% end %>
and finally, you can render this on your file which needs to show the message like
On the top of the page and every page which you need show flash
<%= render partial: "common/flash" %>
Hope to help

fool-dev
- 7,671
- 9
- 40
- 54
-
I appreciate your idea. it's work fine. but it works after reload the page. – Thilanka Umayanga Jayarathna Jan 05 '18 at 09:48
-
You need to implement some js code for this & that's why you need to learn basic ror & js – fool-dev Jan 05 '18 at 10:06
-
@ThilankaUmayangaJayarathna For show flash without page load please see SO answer https://stackoverflow.com/a/27810176/4172515 https://stackoverflow.com/a/23967474/4172515 – fool-dev Jan 05 '18 at 10:12
-
Thanks and appreciate. your answer work fine when layout false. I had a misunderstand about flash messages – Thilanka Umayanga Jayarathna Jan 08 '18 at 07:18