Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
like image 543
Manjunath Manoharan Avatar asked Aug 14 '11 04:08

Manjunath Manoharan


People also ask

How does Link_to work in Rails?

Rails is able to map any object that you pass into link_to by its model. It actually has nothing to do with the view that you use it in. It knows that an instance of the Profile class should map to the /profiles/:id path when generating a URL.

What is Link_to?

In computing, a hyperlink, or simply a link, is a reference to data that the user can follow by clicking or tapping. A hyperlink points to a whole document or to a specific element within a document. Hypertext is text with hyperlinks.

How do I link pages in Ruby on Rails?

open index. html. erb file in app>>views>>home folder use in atom editor. After you open index file now add following HTML link code in that file and end with <br /> tag.

How do I create a link in rails?

The rails link_to is a helper which helps us in creating a hyperlink to the existing main document. The Rain link_to will be created as anchor tag or the h-ref tag. Anchor tag is known as an HTML code that creates another link to another page or to a specific section of the existing document.


1 Answers

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.

like image 147
Jake Dempsey Avatar answered Oct 12 '22 15:10

Jake Dempsey