问题是当我点击链接时,URL看起来像:
/show?id=1&slug=aasdasd
但应该是:
/strona/1/aasdasd
在routes.rb
中match "strona/:id/:slug", :controller => "subpages", :action => "show", :via => :get
在application_controller.rb中:
def subpages
Subpage.all
end
在application.html.erb中:
<% subpages.each do |subpage| %>
<%= link_to subpage.title, {:controller => 'subpages', :action => 'show', :id => subpage.id, :slug => subpage.title.parameterize} %>
<% end %>
有什么想法吗?
答案 0 :(得分:1)
Routes.rb(为您的路径添加“:as =&gt;:strona”):
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) %>