看过一些参考资料,但它是旧的 Rails 2 解决方案。很难理解一些 Rails 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.
谢谢您的帮助!