ruby-on-rails – Rails从Controller重定向到Anchor标签

ruby-on-rails – Rails从Controller重定向到Anchor标签,第1张

概述我使用Comments表作为多态关联.当我保存评论并重定向到相应的关联模型.我希望它传递一个锚标记自动向下滚动以显示注释.我尝试以下但锚标签没有传递到网址 @comment = @commentable.comments.new comment_params @comment.user = current_user @comment.save redirect_to @co 我使用Comments表作为多态关联.当我保存评论并重定向到相应的关联模型.我希望它传递一个锚标记自动向下滚动以显示注释.我尝试以下但锚标签没有传递到网址

@comment = @commentable.comments.new comment_params    @comment.user = current_user    @comment.save    redirect_to @commentable,:anchor => '#comments'

耙路

Prefix Verb   URI Pattern                                   Controller#Action                    rate POST   /rate(.:format)                               rater#create        new_user_session GET    /users/sign_in(.:format)                      devise/sessions#new            user_session POST   /users/sign_in(.:format)                      devise/sessions#create    destroy_user_session DELETE /users/sign_out(.:format)                     devise/sessions#destroy           user_password POST   /users/password(.:format)                     devise/passwords#create       new_user_password GET    /users/password/new(.:format)                 devise/passwords#new      edit_user_password GET    /users/password/edit(.:format)                devise/passwords#edit                         PATCH  /users/password(.:format)                     devise/passwords#update                         PUT    /users/password(.:format)                     devise/passwords#updatecancel_user_registration GET    /users/cancel(.:format)                       devise/registrations#cancel       user_registration POST   /users(.:format)                              devise/registrations#create   new_user_registration GET    /users/sign_up(.:format)                      devise/registrations#new  edit_user_registration GET    /users/edit(.:format)                         devise/registrations#edit                         PATCH  /users(.:format)                              devise/registrations#update                         PUT    /users(.:format)                              devise/registrations#update                         DELETE /users(.:format)                              devise/registrations#destroy                    root GET    /                                             welcome#index                 artists GET    /artists(.:format)                            artists#index                         POST   /artists(.:format)                            artists#create              new_artist GET    /artists/new(.:format)                        artists#new             edit_artist GET    /artists/:ID/edit(.:format)                   artists#edit                  artist GET    /artists/:ID(.:format)                        artists#show                         PATCH  /artists/:ID(.:format)                        artists#update                         PUT    /artists/:ID(.:format)                        artists#update                         DELETE /artists/:ID(.:format)                        artists#destroy          album_comments GET    /albums/:album_ID/comments(.:format)          albums/comments#index                         POST   /albums/:album_ID/comments(.:format)          albums/comments#create       new_album_comment GET    /albums/:album_ID/comments/new(.:format)      albums/comments#new      edit_album_comment GET    /albums/:album_ID/comments/:ID/edit(.:format) albums/comments#edit           album_comment GET    /albums/:album_ID/comments/:ID(.:format)      albums/comments#show                         PATCH  /albums/:album_ID/comments/:ID(.:format)      albums/comments#update                         PUT    /albums/:album_ID/comments/:ID(.:format)      albums/comments#update                         DELETE /albums/:album_ID/comments/:ID(.:format)      albums/comments#destroy                  albums GET    /albums(.:format)                             albums#index                         POST   /albums(.:format)                             albums#create               new_album GET    /albums/new(.:format)                         albums#new              edit_album GET    /albums/:ID/edit(.:format)                    albums#edit                   album GET    /albums/:ID(.:format)                         albums#show                         PATCH  /albums/:ID(.:format)                         albums#update                         PUT    /albums/:ID(.:format)                         albums#update                         DELETE /albums/:ID(.:format)                         albums#destroy           song_comments GET    /songs/:song_ID/comments(.:format)            songs/comments#index                         POST   /songs/:song_ID/comments(.:format)            songs/comments#create        new_song_comment GET    /songs/:song_ID/comments/new(.:format)        songs/comments#new       edit_song_comment GET    /songs/:song_ID/comments/:ID/edit(.:format)   songs/comments#edit            song_comment GET    /songs/:song_ID/comments/:ID(.:format)        songs/comments#show                         PATCH  /songs/:song_ID/comments/:ID(.:format)        songs/comments#update                         PUT    /songs/:song_ID/comments/:ID(.:format)        songs/comments#update                         DELETE /songs/:song_ID/comments/:ID(.:format)        songs/comments#destroy                   songs GET    /songs(.:format)                              songs#index                         POST   /songs(.:format)                              songs#create                new_song GET    /songs/new(.:format)                          songs#new               edit_song GET    /songs/:ID/edit(.:format)                     songs#edit                    song GET    /songs/:ID(.:format)                          songs#show                         PATCH  /songs/:ID(.:format)                          songs#update                         PUT    /songs/:ID(.:format)                          songs#update                         DELETE /songs/:ID(.:format)                          songs#destroy                         GET    /get_albums_of_artist/:artist_ID(.:format)    songs#get_albums_of_artist
解决方法 删除锚点字符串中的#符号并在url helper方法中调用anchor:redirect_to comments_path(anchor:’anchor_tag’) 总结

以上是内存溢出为你收集整理的ruby-on-rails – Rails从Controller重定向到Anchor标签全部内容,希望文章能够帮你解决ruby-on-rails – Rails从Controller重定向到Anchor标签所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1241840.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存