gpt4 book ai didi

ruby-on-rails - 动态 body ID

转载 作者:数据小太阳 更新时间:2023-10-29 06:55:17 26 4
gpt4 key购买 nike

如何在 Rails 中为 body 标签设置 ID?

<body id="login">

最佳答案

我没有发现任何特别优雅或灵活的解决方案。将 body_class 方法添加到 application_helper.rb:

  def body_class
[controller_name, action_name].join('-')
end

..在布局中:

<body class="<%= body_class %>">
#e.g output: <body class="articles-show">

然后您可以改进上述帮助程序以动态注入(inject)其他标识符,例如模块。

关于ruby-on-rails - 动态 body ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com