Rails link_to anchor with remote: true & method: :post

我们两清 提交于 2019-12-11 04:45:10

问题


The anchor doesn't work with method: :post for some reason.

My view file index.haml:

/ some code here
%h3= Description
.results
  =render 'result_box'

_result_box.haml partial:

.row#scroll-here
  .col-md-12
    = link_to "Get result", get_result_path(@book, :anchor => "scroll-here", parameters: {first: 1, second: 2}), method: :post, remote: true

index.js.erb :

$('.results').html("<%= j (render partial: 'result_box') %>")

After pressing link_to and reloading ".results" the page focus is still on the top of the page. But I want it to be at the "#scroll-here".


回答1:


try this

 = link_to "Get result", get_result_path(@book, :anchor => "scroll-here", parameters: {first: 1, second: 2}), method: :post,{ remote: true}

or

= link_to "Get result", get_result_path(@book, :anchor => "scroll-here", parameters: {first: 1, second: 2}), method: :post,:remote=> true

Refer this link (http://haml.info/docs/yardoc/file.REFERENCE.html#inserting_ruby_)



来源:https://stackoverflow.com/questions/36568609/rails-link-to-anchor-with-remote-true-method-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!