【发布时间】:2015-07-09 01:03:25
【问题描述】:
执行摘要
- 通过蛮力猜测,读取 API 并获得有效的“link_to”。
- 提供 API 和描述,并试图弄清楚我的蛮力猜测是如何起作用的!?
== 结束
我正在尝试学习“如何在 Rails 中阅读 API 文档”。一个给我带来很多麻烦的特定功能是 link_to 功能。简单明了,我只需要学习如何“读取 api 函数”,这个问题与此有关。
网址:http://apidock.com/rails/v4.0.2/ActionView/Helpers/UrlHelper/link_to
当前文档详细介绍了以下内容
1. link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path
2. link_to(body, url_options = {}, html_options = {})
# url_options, except :method, is passed to url_for
3. link_to(options = {}, html_options = {}) do
# name
end
4. link_to(url, html_options = {}) do
# name
end
最后,我想使用 DO 块添加一大堆 HTML 样式并利用 AJAX 到我的 link_to 功能。
这是行得通的,但我只是不明白为什么根据原型使用选项 #4 而不是选项 #3?
成功了:
<%= link_to session_path(@account.id), {remote: true, :method => :delete, id: "abc",style: "display:inline-block; top: 20px; color: red; outline: none;" } do %>
<span class="glyphicon glyphicon-log-out" style: "display:inline-block; top: 20px; color: red; outline: none;"></span>
<span id="nav_loginout_action" style= "top: 20px; color: none; outline: none;display:inline-block;margin-left: 5px;">
Logout </span>
<% end %>
这不是
但是,如果您注意到 {remote:true, method => delete} 用于 OPTIONS,{id: "abc",style: "display:inline-block; top: 20px; color: red; outline: none;"} 用于 HTML_OPTIONS
<%= link_to session_path(1), {remote: true, :method => :delete}, {id: "abc",style: "display:inline-block; top: 20px; color: red; outline: none;" } do %>
<span class="glyphicon glyphicon-log-out" style: "display:inline-block; top: 20px; color: red; outline: none;"></span>
<span id="nav_loginout_action" style= "top: 20px; color: none; outline: none;display:inline-block;margin-left: 5px;">
Logout </span>
<% end %>
谁能解释如何阅读 Rails 文档?
特别是
这让我很困扰:
In the documentation OPTIONS = {} is specifically defined as ".... :data, :method and remote:true.
在 OPTION 4 中,它需要一个 HTML_OPTION(**不是 OPTIONS,这是在选项 #3 ** 中特别要求的)。请参阅提供的 URL 链接
唯一并重复提到 OPTIONS 哈希的唯一地方是 OPTION 3!我最初尝试使用选项#3,但我不确定#name 是什么。那是另一个问题......(我想知道)。但目前的主要问题是 HTML_OPTIONS 如何神奇地表示 OPTIONS。
我担心我不知道如何阅读其中一些文档,因此我获得自助的能力有限。请帮忙。
【问题讨论】:
-
这让我很困扰:OPTIONS = {} 在帮助中定义为“选项定义为 .... :data, :method 和 remote:true。在 OPTION 4 中它需要一个 HTML_OPTION (**不是 OPTIONS,这是在选项 #3 中特别要求的**)。
标签: ruby-on-rails ruby ruby-on-rails-4