我有一个带有评论功能的博客应用程序。 目前,评论控制器具有标准的创建操作。
def create
@comment = current_user.build(params[:comment])
respond_to do |format|
if @comment.save
format.html { redirect_to @comment.post }
end
end
创建评论后,用户将被重定向到所评论的博客文章页面。如何将重定向位置下移,以便到达新评论所在的位置? posts/show.html.erb
<div id="post_show">
<%= @post.content %>
<%= render @post.comments %>
</div>
comments/_comment.html.erb
<div id="comment_partial">
<%= comment.content %>
</div>
有没有什么我可以添加到我的HTML中,然后在我的控制器中引用?我需要以某种方式“保存”位置吗?感谢帮助新手!
<div id="comment_12345">
,那么您可以将#comment_12345附加到URL上,这将确保页面上具有IDcomment_12345
的任何元素都会滚动到。 - Christopher.Cubells