开发者

Route in Rails: bad URL

开发者 https://www.devze.com 2023-03-29 21:07 出处:网络
The problem is that when I click on the link, the URL looks like: /show?id=1&slug=aasdasd But should be:

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

精彩评论

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