为什么Rails会在anchor元素的属性href
中创建当前页面的路径,而不是在发送异常时向我的link_to
方法传递与任何资源无关的实例变量(和等于nil
)?Ruby on Rails。 link_to不会引发异常
下面是一个例子:
路线
# 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;
Ruby 1.9.2;
Ruby on Rails 3.0.6。