私は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タグ/レールがルートtags/:idを指していることはわかっています.link_toに追加のパラメータを提供して、タグ名を:idパラメータとして割り当てましたが、ご覧のとおり、機能していません. フォーラムでは to_param を使用するよう提案されましたが、Tag モデルがなく、本ではそれに対して提案されていません。何か不足していますか?
私はSitepointの本Simply Rails 2に従っています
編集:作業 URL を追加、上部を参照