开发者

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) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜