简体   繁体   English

Rails link_to 锚点与远程:true 和方法::post

[英]Rails link_to anchor with remote: true & method: :post

The anchor doesn't work with method: :post for some reason.由于某种原因,锚点不适用于 method::post。

My view file index.haml:我的视图文件 index.haml:

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

_result_box.haml partial: _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 : 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.按 link_to 并重新加载“.results”后,页面焦点仍位于页面顶部。 But I want it to be at the "#scroll-here".但我希望它位于“#scroll-here”。

<%= link_to "Get Result", path(id: params[:id]), class: "", method: :post, remote: true %>

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_ )请参阅此链接( http://haml.info/docs/yardoc/file.REFERENCE.html#inserting_ruby_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM