使用Rails / Link_to / Haml / turbo-links传递两个参数

时间:2013-09-12 19:50:50

标签: ruby-on-rails haml link-to turbolinks

我正在尝试传递两个参数data-no-turbolinksmobile

这有效:

(1)%a{href: "#{test_path}", data: { no: { turbolink: true }}} %span Test

转换为

<a data-no-turbolink href='/test'> <span>Test</span></a>

现在我需要在此链接中添加一个参数:mobile

以下所有内容均无效!

(1)%a{href: "", mobile: 1, data: { no: { turbolink: true }}}

 %a{href: "", data: {mobile: 1, no: { turbolink: true }}}

(turbo-link正确传递,而非移动设备)

(2)%span= link_to "Mobile", {mobile: 1, data: { no: { turbolink: true }}}

(3)%span= link_to "Mobile", {'mobile' => 1, 'data-no-turbolink' => true }

(4)%span= link_to "Mobile", url_for('mobile' => 1, 'data-no-turbolink' => true)

(5)%span= link_to "Mobile", data: {mobile: 1, no: {turbolink: true} }

2 个答案:

答案 0 :(得分:0)

= link_to "Mobile", '#', {"data-mobile" => "1", "data-no-turbolink" => "true"}

输出

<a href="#" data-no-turbolink="true" data-mobile="1">

答案 1 :(得分:0)

我正在使用slim,我使用

解决了这个问题
ol data-no-turbolink=true #// here ol is unorders list tag for my case