Route in Rails: bad URL
The problem is that when I click on the link, the URL looks like:
/show?id=1&slug=aasdasd
But should be:
/strona/1/aasdasd
In routes.rb
match "strona/:id/:slug", :controller => "subpages", :action => "show", :via => :get
In application_controller.rb:
def subpages
Subpage.all
end
In application.html.erb:
<% subpages.each do |subpage| %>
<%= link_to subpage.开发者_运维知识库title, {:controller => 'subpages', :action => 'show', :id => subpage.id, :slug => subpage.title.parameterize} %>
<% end %>
Any ideas?
Routes.rb (add ":as => :strona" for your path):
match "strona/:id/:slug", :controller => "subpages", :action => "show", :via => :get, :as => :strona
View.html.erb:
<%= link_to subpage.title, strona_path(subpage.id, subpage.title.parameterize) %>
精彩评论