【发布时间】:2012-05-15 14:03:28
【问题描述】:
为什么 Rails 会在锚元素的 href 属性中创建指向当前页面的路径,而不是在我向 link_to 方法传递一个不与任何资源关联的实例变量时引发异常(并且等于nil)?
这是一个例子:
路线
# app/config/routes.rb
Example::Application.routes.draw do
resource :example
end
HAML
-# app/views/examples/show.html.haml
%div
= link_to 'Non-existent resource', @ne_resource
HTML
<!-- http://localhost/example -->
<div>
<a href="/example">Non-existent resource</a>
谢谢。
Debian GNU/Linux 6.0.1;
红宝石 1.9.2;
Ruby on Rails 3.0.6。
【问题讨论】:
标签: ruby-on-rails helpers