【问题标题】:how to use variables inside loop in haml?如何在haml的循环中使用变量?
【发布时间】:2010-10-14 04:35:27
【问题描述】:

如何在第二行中使用变量 file 的值而不是 both 字符串 file

- files.each do |file| 
  %a(href="test?run=file")click file 

【问题讨论】:

    标签: ruby haml


    【解决方案1】:
    - files.each do |file|
      %a(href="test?run=file")
        click
        = file
    

    === 更新 ===

    - files.each do |file|
      %a(href="test?run=#{file}")
        click
        = file
    

    或使用link_to 代替%a

    - files.each do |file|
      = link_to "test?run=#{file}" do
        click
        = file
    

    【讨论】:

    • @PeterWong:在我看来你错过了第二个|。我遇到了一个错误,但使用结束 | 解决了这个问题。我想用变量值的值替换两个字符串文件。我可以这样做吗?
    • 更新了答案。抱歉错过了第二个|,将其添加回来:D
    • @PeterWong:正是我想要的。谢谢你。你能为我推荐任何haml教程吗?
    • 您可以执行“== click #{file}”而不是 click and = file on单独的行
    • @Jason Noble:== 有什么作用?即使我想用粗体显示“文件”但不点击,我可以使用这一行吗?
    猜你喜欢
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多