当我的视图文件中有这样的链接时,怎么会这样:
<%= link_to image_tag("foo.png"), :url => new_foo_path, :class => "banner-image" %>
生成的标记会产生一个无效的锚标记,如下所示:
<a href="/home/index?class=banner-image&url=http%3A%2F%2Flocalhost%3A3000%2Ffoo%2Fnew"><img alt="foo" src="/assets/foo.png"></a>
但如果我这样做:
<%= link_to image_tag("foo.png"), url_for({:controller => "foo", :action => "new"}), :class => "banner-image" %>
它完美地工作 - 这产生了:
<a href="/foo/new" class="banner-image"><img alt="foo" src="/assets/foo.png"></a>
我的 routes.rb 包含 foo 的这一行:
resources :foo, only: [:new, :create]