1

this works nicely

= link_to 'All', test_path(:param1 => xxx), 'data-no-turbolink' => true

and translates to

 <a data-no-turbolink="true" href="/test?param1=xxx">All</a>

I want to change it to the new hash syntax so I did this:

= link_to 'All', test_path(param1: xxx), data: { no: { turbolink: true }}

but it translates to

<a data-no="{&quot;turbolink&quot;:true}" href="/test?param1=xxx">All</a>

EDIT: This Works:

%a{href: "#{test_path(param1: xxx}", data: { no: { turbolink: true }}} All

which translates to

<a data-no-turbolink href='/test?param1=xxx'>All</a>

but shouldn't I stick to link_to rather than <a href></a>?

4

2 回答 2

2

有一些命名约定,所以你必须这样写:

link_to 'All', test_path(param1: xxx), data: {no_turbolink: true}
于 2013-09-17T00:20:48.213 回答
1

当 Rails 辅助方法可用时,您应该始终尝试使用它们。通过这种方式,您将获得 Rails 的所有好处:缓存清除和相对路径以及将来会出现的任何其他内容。鉴于此,您的代码中的问题是data哈希只能是一级深度。所以改为这样做:

= link_to 'All', test_path(param1: xxx), data: { 'no-turbolink' => true }

注意:您不能真正为no-turbolink部件使用符号,因为符号不解释连字符。https://gist.github.com/misfo/1072693

于 2013-09-17T01:04:52.567 回答