我正在使用友好的网址。
我在访问http://localhost:3000/9时使用了该问题,它显示与http://localhost:3000/vind-rejse相同的页面
我的类别vind-rejse的ID为9
如何仅在http://localhost:3000/vind-rejse上回复?
如何链接到konkurrancers show action?
我的Kategoris控制器:
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'
答案 0 :(得分:1)
这样的事情会起作用:
@kategori = Kategori.find_by_name!(params[:id])
和您的路线
match ':kategoris/:id' => 'konkurrancers#show', :as => 'whatever'
并在您的观看中
<%= link_to "Whatever", whatever_path(9) %>