How do I create a link that passes an ID for a custom action in Rails?0 <%= link_to "PDF", :action => "showpdf", :id => "#{@letter.id}.pdf" %>
I have the following code:
<%= link_to "PDF", :action => "showpdf", :id => "#{@letter.id}.pdf" %>
'showpdf' is an action in my Letters controller.
My expectation is that this link should yield the following:
http://domain.c开发者_高级运维om/letters/showpdf/id.pdf
But instead, I get:
http://domain.com/letters/showpdf?id.pdf
If the default routes are :controller/:action/:id shouldn't this work?
Do I need to do something in the routes, even though the format for default appear right? Thanks!
Have you tried something like:
<%= link_to "PDF", :action => "show", :id => letter.id, :format => :pdf %>
where your route would be
:controller/:action/:id.:format
and in your controllers "show" action:
respond_to do |format|
format.pdf .....
format.html .....
end
精彩评论