Manjunath Manoharan
Manjunath Manoharan

Reputation: 4617

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

Upvotes: 28

Views: 19444

Answers (1)

Jake Dempsey
Jake Dempsey

Reputation: 6312

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

include Rails.application.routes.url_helpers
# => Object
default_url_options[:host] = "localhost"
# => "localhost"
profiles_url(:anchor => "moo")
# => "http://localhost/profiles#moo"

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.

Upvotes: 45

Related Questions