简体   繁体   中英

Rails: Anchor option and link_to

I have a link_to method in Rails

link_to("feedback", meetings_url(:anchor => "sometext"))

=> The above code produces:

<a href="/p/meeting/?scroll_to=sometext">feedback</a>

I thought anchor was supposed to prepend a hash paramter, something like this:

/p/meeting/#sometext

I just tried in the console and I get the expected #anchor

irb(main):009:0> include Rails.application.routes.url_helpers
=> Object
irb(main):010:0> default_url_options[:host] = "localhost"
=> "localhost"
irb(main):011:0> profiles_url(:anchor => "moo")
=> "http://localhost/profiles#moo"
irb(main):012:0>

What version of rails are you using? Do yo maybe have a gem or plugin that is overriding your link_to helper? You could create an empty rails app, and try the above test to see if something else is causing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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