Reputation: 2353
I need to place all my flash notices below header, except of one page.
Only on one page I should place it differently.
EDIT
I added in my acton, where I want to use another layout this line:
render :layout => 'show'
and now, when I'm going to show page it gives me:
undefined method `url' for nil:NilClass
but without rendering THIS layout - no errors.
EDIT
Is it possible in Rails ?
Upvotes: 0
Views: 1554
Reputation: 1198
This is very easy to show flash message anywhere
<% flash.each do |name, msg| %>
<%= content_tag :div, msg, class: "flash notice" , id:"flash_notice" %>
<% end %>
here is css for flash message
div.flash.notice {
background: url(../images/true.png) 8px 5px no-repeat;
background-color: #dfffdf;
border-color: #9fcf9f;
color: #005f00;
}
Upvotes: 0
Reputation: 9454
Off the top of my head, you could just do a check on the current controller#action in the view to see if our flash messages need to be moved.
Rails passes these params to every view (ex: if we were in the show
action of UsersController
):
params[:controller] #=> users
params[:action] #=> show
We could add a helper to simplify our condition in the view:
# file: app/helpers/application_helper.rb
def move_flash_messages?
params[:controller] == "users" && params[:action] == "show"
end
And then do this simple check in our layout:
# file: app/views/layouts/application.html.haml
- unless move_flash_messages?
= flash_messages
...
- if move_flash_messages?
= flash_messages
Upvotes: 2