在 haml 文件中将 ruby​​ 参数连接到对象 ID?

发布于 2024-12-05 02:06:13 字数 272 浏览 4 评论 0原文

我在 Rails 上使用 ruby​​。

这是我的“视图”代码(file.haml)的一部分:

%div#all_ads
  - @ads.each_with_index do |ad,index|   
    %div#campaign_ads

我想将索引连接到div id。

%div#campaign_ads+index

语法必须是什么?

I work with ruby on rails.

this is part of my 'view' code (file.haml):

%div#all_ads
  - @ads.each_with_index do |ad,index|   
    %div#campaign_ads

I want to concatenate the index to the div id.

something like %div#campaign_ads+index

what have to be the syntax?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小猫一只 2024-12-12 02:06:13

像这样的东西:

#all_ads
  - @ads.each_with_index do |ad, index|   
    %div{:id => "campaign_ads#{index}"}

Something like this:

#all_ads
  - @ads.each_with_index do |ad, index|   
    %div{:id => "campaign_ads#{index}"}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文