Is it possible to get the root page scroll to an anchor link when it loads the first time?
in my routes.rb file, i did
root :to => 'home#index#header' (#header being the anchor element in the index.html.erb)
But, obviously, that did not work.
Is it possible to get the root page scroll to an anchor link when it loads the first time?
in my routes.rb file, i did
root :to => 'home#index#header' (#header being the anchor element in the index.html.erb)
But, obviously, that did not work.
You could do that in your controller by passing an :anchor
parameter to any URL helper. See How do you use anchors for IDs in routes in Rails 3? for a nice example.
You could also do that via javascript directly in the view (where it belongs IMO).
So no, I don't know a way to do that in your routes.rb
but even if I did I would suggest against it. In your routes you are wiring incoming requests to controllers and actions. An HTML anchor is a view-related thing so it doesn't belong to routes.rb
.
Use Javascript: (actually Coffeescript):
$(document).on 'turbolinks:load', ->
window.location.hash = '#my_anchor'