新手问题 Rails 中 link_to 问题

supiccc · February 13, 2017 · Last by supiccc replied at February 13, 2017 · 947 hits

在 Rails 入门那里看到删除评论的代码

<%= link_to 'Destroy Comment', [comment.article, comment], method: :delete, data: { confirm: 'Are u sure?' } %>

[comment.article, comment] 这个地方很难理解,例如

<p><%= link_to 'Back', articles_path %></p>

都是直接填写地址,为什么这里用一个数组表示,又表示什么意思? 小白求解答

rails/ActionView/RoutingUrlFor/url_for source code. 是不是这个 url_for 不确定 (有好几个),但是思想肯定是这个。

他下面不是解释了吗

fire off a DELETE /articles/:article_id/comments/:id to our CommentsController

#1 楼 @flowerwrong

<%= url_for(@workshop) %>
# calls @workshop.to_param which by default returns the id
# => /workshops/5

我想应该是这个吧,[comment.article, comment] 连起来表示/articles/:article_id/comments/:id

supiccc closed this topic. 13 Feb 23:29
You need to Sign in before reply, if you don't have an account, please Sign up first.