Rails friendly Url how to prevent duplicates? and routing
I am using friendly url.
I am using that problem when I visit http://localhost:3000/9 it shows the same page as http://localhost:3000/vind-rejse
My Category vind-rejse have the ID of 9
How do I get rails only to respond on http://localhost:3000/vind-rejse?
And how do I link to konkurrancers show action?
My Kategoris controller:
def show
@kategori = Kategori.find(params[:id])
@konkurrancer = @kategori.konkurrancers.find(:all)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @kategori }
end
end
My Konkurrancers controller:
def show
@konkurrancer = Konkurrancer.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { r开发者_Python百科ender :xml => @konkurrancer }
end
end
My routes:
match ':kategoris/:id' => 'konkurrancers#show'
match '/:id' => 'kategoris#show'
Something like this will work:
@kategori = Kategori.find_by_name!(params[:id])
and for your routes
match ':kategoris/:id' => 'konkurrancers#show', :as => 'whatever'
and in your views
<%= link_to "Whatever", whatever_path(9) %>
精彩评论