我正在尝试创建指向特定页面部分ID的链接。在rails中创建html锚点
这有点像波纹管的HTML,但我想用轨道,而不是...
<a id="tips">Useful Tips Section</a>
<a href="#tips">Visit the Useful Tips Section</a>
我怎么可以指定的link_to功能的“#tips”?或者我应该创建一个特定的路线?怎么样?
在此先感谢
我正在尝试创建指向特定页面部分ID的链接。在rails中创建html锚点
这有点像波纹管的HTML,但我想用轨道,而不是...
<a id="tips">Useful Tips Section</a>
<a href="#tips">Visit the Useful Tips Section</a>
我怎么可以指定的link_to功能的“#tips”?或者我应该创建一个特定的路线?怎么样?
在此先感谢
您可以使用
<%= link_to "Visit the Useful Tips Section", action_path(anchor: tips) %>
在路线您可以指定action_path
。
按照Rails的API文档,你应该做上述方式,请参阅this,并找到下面的例子:
link_to "Comment wall", profile_path(@profile, anchor: "wall")
# => <a href="/profiles/1#wall">Comment wall</a>
尝试使用的link_to
<%= link_to "Visit the Useful Tips Section","/#tips" %>
假设您链接到了ID在同一页上
<%= link_to('new button', action: 'login' , class: "text-center") %>
创造了login.html的一个锚标记灌胃
<a href="login.html" class = "text-center"> new button </a>
和
<a href="admin/login.html" class = "text-center"> new button </a>
使用
<%= link_to('new button', controller: 'admin',
action: 'login' , class: "text-center") %>