简体   繁体   中英

Correct use of anchor in rails to link_to different page

I am trying to use correctly :anchor in my Rails app but I can't get it work correctly.

my example:

<% = link_to('Artist Page', artists_path(artist, :anchor => 'ranking')) %>

and the link I get:

/artists.1-young-the-giant#ranking

instead of:

/artists/1-young-the-giant#ranking

So I am getting a "dot" instead or a "forward slash".

I have search a lot inside stackoverflow and I see similar examples with same result.

Any idea?

I am using the last version of Rails. Thank you so much.

Try

<% = link_to('Artist Page', artist_path(artist, :anchor => 'ranking')) %>

artist_path should be singular as you're not querying the index action.

Check out this part of Rails guides for more info:

http://guides.rubyonrails.org/routing.html#path-and-url-helpers

These are the paths generated for you when you use the resource keyword in your routes:

artists_path returns /artists
new_artist_path returns /artists/new
edit_artist_path(:id) returns /artists/:id/edit
artist_path(:id) returns /artists/:id

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