Using turbolinks in a Rails link_to

前端 未结 6 1230
臣服心动
臣服心动 2020-11-29 03:14

Just wondering whether there\'s a way to use turbolinks directly in a rails link_to helper, a quick bit of googling didn\'t uncover anything of note, here\'s the type of thi

6条回答
  •  情深已故
    2020-11-29 04:01

    Edit for Rails 5+: @ManishShrivastava correctly pointed out the different syntax needed for Rails 5 as shown in Joseph's answer.

    <%= link_to('Giraffe', @giraffe, data: { turbolinks: false }) %>

    For Rails 4 and below

    Originally I thought you needed to use the hash rocket syntax for the symbol but that isn't the case. You can use a data: hash and inside that hash any symbols using underscores _ will be converted to dashes -.

    I think most Rails developers would prefer to see the following (including myself now that I know better):

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

    But the following also works:

    <%= link_to('Giraffe', @giraffe, 'data-no-turbolink' => true) %>

提交回复
热议问题