【发布时间】:2011-02-17 21:40:43
【问题描述】:
我正在使用acts_as_taggable_on 类固醇,我对生成标签链接的这段代码有问题:
<%= link_to tag, tag_path(:id => tag.name) %>
当我访问 URL 时:
http://localhost:3000/tags/rails
我得到错误:
No action responded to rails. Actions: show
但是,此 URL 有效:
http://localhost:3000/tags/show/rails
我已经在我的 tags_controller.rb 中定义了 show 动作
class TagsController < ApplicationController
def show
@stories = Story.find_tagged_with(params[:id])
end
end
我有以下由 rake:routes 生成的路由:
tags GET /tags(.:format) {:controller=>"tags", :action=>"index"}
POST /tags(.:format) {:controller=>"tags", :action=>"create"}
new_tag GET /tags/new(.:format) {:controller=>"tags", :action=>"new"}
edit_tag GET /tags/:id/edit(.:format) {:controller=>"tags", :action=>"edit"}
tag GET /tags/:id(.:format) {:controller=>"tags", :action=>"show"}
PUT /tags/:id(.:format) {:controller=>"tags", :action=>"update"}
DELETE /tags/:id(.:format) {:controller=>"tags", :action=>"destroy"}
所以我知道 URL 标记/rails 指向路由标记/:id,并且我为 link_to 提供了一个附加参数以将标记名称分配为 :id 参数,但正如您所见,它不起作用.一个论坛建议我使用 to_param 但我没有 Tag 模型,这本书建议反对它。我错过了什么吗?
我正在关注 Sitepoint 书籍《Simply Rails 2》
编辑:添加了工作网址,见顶部
【问题讨论】:
标签: ruby-on-rails ruby acts-as-taggable-on clean-urls