【问题标题】:Rails/CSS Display flash messages in a main column of a fixed layout with 2 columnsRails/CSS 在具有 2 列的固定布局的主列中显示 Flash 消息
【发布时间】:2010-10-06 00:06:06
【问题描述】:

对于我的 rails 应用程序,我使用具有 2 列(主列和右侧)的固定布局。 目前,Flash 消息显示在内容 div 中,但我想在“主”div 中显示 Flash 消息( main

我不知道这样做最好。事实上,我是否必须创建一个 Flash 消息助手并将其添加到我的所有视图中,我是否必须创建一个部分,以更改布局或是否有其他解决方案?

这是我的 application.html.erb 结构:

...
<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>
...

例如我的观点之一:(home/index.html.erb)

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

感谢您的任何建议!

【问题讨论】:

    标签: ruby-on-rails css


    【解决方案1】:

    想到两个选项:

    1) 使用绝对定位来移动 flash 消息,考虑侧边栏创建的偏移量。

    2) 只需将您的 Flash 消息代码移动到您希望它出现的视图中。这将需要更多的代码重复,但您可以将其放在部分中,这样它最多只能是您视图中的一行。

    【讨论】:

    • 感谢您的回答,我使用了您的第二个想法,更符合我的需求
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    相关资源
    最近更新 更多