views:

36

answers:

1

Hi,

For my rails app, I use a fixed layout with 2 columns (a main and a rightside). For now, flash messages are displayed in the content div but I would like to show flash msg in the "main" div ( main < content < container ).

I don't know what it the best to do it. In fact, did I have to create a flash message helper and add it in all my views, did I have to create a partial, to change something with the layout or is there another solution?

Here is my application.html.erb structure:

...
<body>
  <div id="container">
    <%= render 'layouts/header' %>
    <div id="content">
      <% flash.each do |name, msg| %>
        <%= content_tag :div, msg, :id => "flash_#{name}" %>
      <% end %>
      <%= content_tag :h1, yield(:title) if show_title? %>
      <%= yield %>
    </div>
    <%= render 'layouts/footer' %>
  </div>
</body>
...

and for example one of my views: (home/index.html.erb)

<div id="rightside">
  ...
</div>
<div id="main">
  ... <-- Here I want to display flash!
</div>

Thanks for any suggestions!

+1  A: 

Two options come to mind:

1) Use absolute positioning to move the flash message over, accounting for the offset created by the sidebar.

2) Just move your flash message code over to the view where you want it to appear. This would require more duplication of code, but you could put it in a partial so it'd be a single line in your views at most.

Jimmy Cuadra
Thanks for your answer, I used your second idea which fits better with my needs
benoitr