【发布时间】:2011-07-14 14:24:25
【问题描述】:
我正在使用友好的网址。
我在访问http://localhost:3000/9 时遇到了这个问题,它显示的页面与http://localhost:3000/vind-rejse 相同
我的类别 vind-rejse 的 ID 为 9
如何让 rails 只回复http://localhost:3000/vind-rejse?
我如何链接到 konkurrancers show action?
我的类别控制器:
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'
【问题讨论】:
-
你在使用
def to_param #... end吗? -
是受保护的 def assign_cached_slug self.cached_slug = self.name.gsub(/\s+/, '_').gsub(/[^\w\-]/, '') end def to_param self.name 结束
-
您可以发布您的控制器代码(显示操作)吗?
-
我现在已经发布了两个控制器的显示动作
标签: ruby-on-rails ruby-on-rails-3 friendly-url