看到一些参考,但它的旧的Rails 2解决方案。有足够的时间来理解Rails 3的一些术语。无法添加方法和link_to工作(铁路3)
我在我的控制器中添加了一个'dndl'方法。 我在我的索引中添加了一个link_to。 我试了一次又一次把航线
Controller:
def dnld
blah blah
end
指数:
<td><%= link_to 'Show', stock %></td>
<td><%= link_to 'Edit', edit_stock_path(stock) %></td>
<td><%= link_to 'Dnld', dnld, {:action => 'dnld'} %></td>
<td><%= link_to 'Destroy', stock, :confirm => 'Are you sure?', :method => :delete %>
路线:
resources :stocks do
collection do
put 'dnld'
end
end
我已经试过:
<td><%= link_to 'Dnld', stock, {:action => 'dnld'} %></td>
# End up on the stock show page with dnld not executed to my knowledge
<td><%= link_to 'Dnld', , {:action => 'dnld'} %></td>
# Produces an error
<td><%= link_to 'Dnld', dnld_stock_path(stock), {:action => 'dnld'} %></td>
# It doesn't know what dnld_stock_path is, yet I don't understand why it DOES know what edit_stock_path is and cannot find documentation to explain this.
感谢帮助!
我还需要上面的kishi的答案。我使用了会员电话。但是我认为:as => dnld从上面的kishi是必要的。在link_to中,我使用了:<%= link_to'Dnld',dnld_stock_path(stock)%>这就是我所需要的URL */stocks/2/dnld。从PUT改为GET也能治愈我。我不完全明白为什么(小白),但我得到了我想要的结果。不要忘记tor“耙路”。 – Dwarfer 2011-04-03 17:02:52