Rails 友好的 Url 如何防止重复?和路由
我正在使用友好的网址。
当我访问 http://localhost:3000/9 时,我遇到了这个问题,它显示与 http://localhost:3000/vind-rejse
我的类别 vind-rejse 的 ID 为 9
我如何获取Rails 只响应 http://localhost:3000/vind-rejse?
我如何链接到 konkurrancers 显示操作?
我的类别控制器:
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
我的 Konkurrancers 控制器:
def show
@konkurrancer = Konkurrancer.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @konkurrancer }
end
end
我的路线:
match ':kategoris/:id' => 'konkurrancers#show'
match '/:id' => 'kategoris#show'
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 { render :xml => @konkurrancer }
end
end
My routes:
match ':kategoris/:id' => 'konkurrancers#show'
match '/:id' => 'kategoris#show'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样的事情会起作用:
并且适用于您的路线
和您的视图
Something like this will work:
and for your routes
and in your views