【问题标题】:Override body attribute in HAML覆盖 HAML 中的正文属性
【发布时间】:2013-03-12 22:27:23
【问题描述】:

我目前在 Rails 项目中,我想在不属于布局的视图中覆盖 body 标记中定义的属性。

像这样:

app/views/layouts/application.haml

...header

%body
  = render 'shared/menu'

  .container
    = yield

在另一个视图中。我希望body标签具有某些属性:

app/views/stuff/index.haml

{data: {spy: 'scroll', target: '.d-sidebar', :'twttr-rendered' => 'true'}} << these attributes should apper in the body tag of the layout file. They should only be visible on the sub page

实现这一目标的最简单方法是什么?

【问题讨论】:

    标签: ruby-on-rails ruby haml


    【解决方案1】:

    你可以提供它:

    在布局中

    %body{ yield(:body_attributes) }
    

    在视图中

    - provide(:body_attributes, { class: '', data: {} })
    

    【讨论】:

    • 不幸的是,这个(body..yield 命令)引发了错误'undefined method `map' for "":ActiveSupport::SafeBuffer'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    相关资源
    最近更新 更多