簡體   English   中英

正確使用導軌中的錨鏈接到其他頁面

[英]Correct use of anchor in rails to link_to different page

我試圖在Rails應用程序中正確使用:anchor,但無法正常工作。

我的例子:

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

和我得到的鏈接:

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

代替:

/藝術家/ 1-年輕的巨人排名#

所以我得到的是“點”或“正斜線”。

我在stackoverflow中進行了大量搜索,並且看到了具有相同結果的類似示例。

任何想法?

我正在使用最新版本的Rails。 非常感謝。

嘗試

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

artist_path應該是單數,因為您不查詢索引操作。

查看Rails指南的這一部分以獲取更多信息:

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

這些是在路線中使用resource關鍵字時為您生成的路徑:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM