Rails link_to锚点使用remote:true&method :: post
锚点不适用于方法:: post由于某种原因。
我的视图文件index.haml:
/ some code here %h3= Description .results =render 'result_box'
_result_box.haml部分:
.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("")
按下link_to并重新加载“.results”后,页面焦点仍然位于页面顶部。 但我希望它在“#roll-here”。
试试这个
= link_to "Get result", get_result_path(@book, :anchor => "scroll-here", parameters: {first: 1, second: 2}), method: :post,{ remote: true}
要么
= link_to "Get result", get_result_path(@book, :anchor => "scroll-here", parameters: {first: 1, second: 2}), method: :post,:remote=> true
请参阅此链接( http://haml.info/docs/yardoc/file.REFERENCE.html#inserting_ruby_ )