user1781626
user1781626

Reputation:

sending a parameter with Link_to and Data-no-turbolink

The following is very confusing to me:

The first link is correctly not using turbo links but the query is not being sent The second link is the opposite scenario

 = link_to 'yesturbo_noquery', "/controller/action", "data-no-turbolink" => true,   query: "hello"
 = link_to "noturbo_yesquery", {'data-no-turbolink' => true, :controller => "controller", :action => "action", :query => "hello" }

How do I make both work?

Edit, This works Thanks to Sikachu

 = link_to 'yesturbo_yesquery', controller_action_path(:query => 'hello'), "data-no-turbolink" => true

Upvotes: 3

Views: 5657

Answers (2)

chaitanya
chaitanya

Reputation: 1974

I think following code is more correct:

<%= link_to('Product', @product, data: { no_turbolink: true }) %>

Also following code will works:

<%= link_to('Product', @product, 'data-no-turbolink' => true) %>

Upvotes: 2

sikachu
sikachu

Reputation: 1221

link_to method actually consist of 3 parts:

link_to(name = nil, options = nil, html_options = nil, &block)

From both of the example you wrote there, example 1 mixed in query into the html_options, and example 2 mixed in data-no-turbolink into options.

I think if you changed it to this, it will work:

link_to 'noturbo_yesquery', {:controller => 'controller', :action => 'action', :query => 'query'}, :data-no-turbolink => true

Upvotes: 2

Related Questions