Ruby on Rails link_to 内部 ID [英] Ruby on Rails link_to internal id

查看:46
本文介绍了Ruby on Rails link_to 内部 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 link_to 以正常转到页面上的特定 (html) ID如果我想转到页面上的whatever_id",我可以使用

How do i use a link_to inorder to go to a specific (html) ID on a page normally if i wanted to go to the "whatever_id" on a page i could use

<a href="http://www.example.com/index/mypage#whatever_id>Click Here</a>

但我想使用我的link_to

but i would like to use my link_to

<%= link_to "click here" , {:action => "mypage", :controller => "index" }, :id => "#whatever_id"%> 

辅助方法.有谁知道如何做到这一点?可能吗?

helper methods. Does anyone know how to do this? Is it possible?

Rails 2.3.4

Rails 2.3.4

推荐答案

link_to 可以向 URL 添加锚点.

link_to can add anchors to a URL.

来自文档

link_to "Comment wall", profile_path(@profile, :anchor => "wall")
# => <a href="/profiles/1#wall">Comment wall</a>

在你的情况下,你可能想要,

In your case you probably want,

 <%= link_to "click here" , {:action => "index", :controller => "mypage", :anchor => "whatever" } %>

这篇关于Ruby on Rails link_to 内部 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆