Question

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>?

Was it helpful?

Solution

There are some naming conventions, so you must write like this:

link_to 'All', test_path(param1: xxx), data: {no_turbolink: true}

OTHER TIPS

You should always try to use the rails helper methods when they're available. This way you'll get all the benefits of rails: cache-busting and relative pathing and whatever else comes in the future. Given that, the issue in your code is that the data hash can only be one level deep. So do this instead:

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

Note: You can't really use a symbol for the no-turbolink part because symbols don't interpret hyphens. https://gist.github.com/misfo/1072693

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top