Rails link_to 锚定在部分内

发布于 2024-12-10 01:55:35 字数 711 浏览 0 评论 0原文

在我的 Rails 3 应用程序中,我有一个 link_to,它将用户从其个人资料页面带到设置页面。设置页面包含用于编辑配置文件的表单 :partial。我想做的是让配置文件中的 link_to 将用户带到表单部分中的锚点。我已经尝试过,但遇到了麻烦。

作为我的 link_to 我有:

<%= link_to('Visit the info section', settings_path, {:anchor => 'info'}) %>

在 settings_path 中是 <%= render :partial =>; 'profiles/edit_settings_form' %>

在该部分中是:

<div class="infoBlock" anchor="#info">
</div>

我有一个我认为导致错误的设置路径:

match "/settings" => "settings#show", :as => 'settings'

我尝试将锚点的另一个匹配项添加到“profiles#edit_settings_form”,但它没有工作。有什么想法吗?

In my Rails 3 app I have a link_to that takes the User from their profile page to the settings page. The settings page contains a form :partial for editing a profile. What I'd like to do is have the link_to in the Profile take the User to an anchor in the form partial. I've given it a go but am having trouble.

As my link_to I have:

<%= link_to('Visit the info section', settings_path, {:anchor => 'info'}) %>

Within settings_path is <%= render :partial => 'profiles/edit_settings_form' %>

Within that partial is:

<div class="infoBlock" anchor="#info">
</div>

I have a route for settings that I thought was causing the error:

match "/settings" => "settings#show", :as => 'settings'

I tried adding another match for the anchor to "profiles#edit_settings_form" but it didn't work. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2024-12-17 01:55:35
<div class="infoBlock" anchor="#info">

不是对页面进行锚定的正确方法。正确的语法类似:

<a name="anchor"></a>

现在,当您使用 pagename#anchor 进行页面访问时,它会将您重定向到该块。例如:

<%= link_to "Block in home", :action => "home", :anchor => "anchor" %>
<div class="infoBlock" anchor="#info">

is not proper way to do an anchor to a page. Correct syntax is something similar:

<a name="anchor"></a>

Now when you got to page with pagename#anchor, it redirects you to that block. For example:

<%= link_to "Block in home", :action => "home", :anchor => "anchor" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文