私は多くのチュートリアルを見てきましたが、レールに多相関連を作成する方法については何もしていませんが、今のところ私は、ポリモーフィックな関連にRyan Bates tutorialを以下していると私は私のブログの記事にタグを追加しようと、私はエラーを取得していますプラグイン多型関連レールのパスヘルパーがありません3
を使用したくない
のエラー未定義のメソッドを取得しておきますタグの
undefined method `tags_path' for <class>
routes.rbを
resources :blog do
resources :tags
end
_form.html.erb
<%= form_for([@taggable, @tag]) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
tag.rb
class Tag < ActiveRecord::Base
belongs_to :taggable, :polymorphic => true
end
blog.rb
class Blog < ActiveRecord::Base
has_many :tags, :as => :taggable
end
マイグレーションファイル
class CreateTags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.string :name
t.string :taggable_type
t.integer :taggable_id
t.timestamps
end
end
def self.down
drop_table :tags
end
end
tags_controller.rb
def index
@taggable = find_taggable
@tags = @taggable.tags
end
def find_taggable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
raise ActiveRecord:NoRecord.new("Couldn\'t find it captain!")
end
のRailsのバージョンは何のようなタグ付け宝石を使用しpolymorphic_urlを使用することができますか?そのチュートリアルはほぼ3歳であり、これはRails時には長い時間です。私が知っている最良のガイドは、[Railsガイド](http://guides.rubyonrails.org/association_basics.html)であり、多態的な関連付けを扱っていますが、その全体(短い)を読む価値があります。 –
rails 2.また、古いですが、いくつかの概念はレール3と同じで、なぜエラーが出現しているのか理解しようとしています。あなたが送ったリンクをチェックしてください。これまでのところ、レールAPIでしか見ていない – coletrain