Search code examples
ruby-on-railslink-to

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

Solution

  • 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