Domanda

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

È stato utile?

Soluzione

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

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top