我对以下链接生成器有看法:
- @tags.each do |tag|
= link_to tag.name, :controller => "images", :action => "#{tag.name}"
@tags
是Tag.all
。它显示具有正确名称的链接,鼠标悬停显示例如
http://localhost:3000/Images/tagname
但如果我点击一个错误是:
No route matches {:controller=>"", :action=>""}
当我指定时它怎么能说:controller
是空的:controller => "images"
?
rake 路线(相关部分):
images GET /images(.:format) images#index
POST /images(.:format) images#create
new_image GET /images/new(.:format) images#new
edit_image GET /images/:id/edit(.:format) images#edit
image GET /images/:id(.:format) images#show
PUT /images/:id(.:format) images#update
DELETE /images/:id(.:format) images#destroy
tags GET /Images(.:format) tags#index
POST /Images(.:format) tags#create
new_tag GET /Images/new(.:format) tags#new
edit_tag GET /Images/:id/edit(.:format) tags#edit
tag GET /Images/:id(.:format) tags#show
PUT /Images/:id(.:format) tags#update
DELETE /Images/:id(.:format) tags#destroy
一个标签,例如“ saturn
”,所以我也添加了这条路线routes.rb
:
match '/Images/saturn' => 'images#saturn'
这导致:
Images_saturn /Images/saturn(.:format) images#saturn
我的图像控制器中也有一个方法“ saturn
”。