Tag:

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”。

如何将锚添加到redirect_to:back

我有一个博客应用程序,其post可以通过post控制器中的vote操作接收投票。 因为我允许在索引和显示视图中进行投票,所以我在进行投票后redirect_to :back ,如下所示。 def vote # voting logic goes here redirect_to :back end 这会将我重定向到正确的页面,但我想重定向到页面中的特定post。 为此,我在post部分div中添加了一个识别锚点。 <div id="post_”> 我怎样才能在redirect_to :back引用它redirect_to :back ? 我尝试了以下,这是行不通的。 # this doesn’t work! redirect_to :back, anchor: “post_#{@post.id}” 或者,如果我对show和index视图使用if子句,我该怎么做? 我尝试了下面的内容,它undefined method ‘current_page’ for VocabsController返回undefined method ‘current_page’ for VocabsController 。 #this doesn’t work! if current_page?(posts_path) redirect_to posts_path(anchor: “post_#{@post.id}” else redirect_to @post end