ユーザーが投稿して記事に適用できる投票間のポリモーフィックな関係を作成しようとしています。私のコード
class Vote < ActiveRecord::Base
attr_accessible :value, :voteable_id, :voteable_type
belongs_to :voteable, :polymorphic => true
end
class User < ActiveRecord::Base
has_many :votes, :as => :voteable
end
class Article < ActiveRecord::Base
has_many :votes, :as => :voteable
end
<Vote id: 1, value: 1, created_at: "2012-07-27 03:13:14", updated_at: "2012-07-27 03:13:14", voteable_id: nil, voteable_type: nil>
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations経由でレールのドキュメントを見ることから
コードは正しく設定されていると思いますが、コードを正しくトリガーするのに少し問題があります。つまり、記事またはユーザーとの関係を適切に定義した投票オブジェクトを実際に作成するにはどうすればよいですか?