継承されたリソースを使用するのは初めてで、ポリモーフィックなネストされたコメントに使用したいと考えています。コメント可能なオブジェクト (記事、ギャラリーなど) がいくつかあり、コメントをネストすることもできます。awesome_nested_set (parent_id, lft, rgt) と多態的なコメント可能な列を持つ Comment モデルを組み合わせて使用しています。
コントローラーは、作成アクションの AJAX 要求 (のみ) を受信し、以下のように実行する必要があります。
/articles/12/comments/34に投稿すると、commentable が @article (12) に、parent が @comment (34) に等しいコメントが作成されます。
/記事/12/コメント/34
/gallery/12/comments/34に投稿 すると、commentable が @gallery (12) に、parent が @comment (34) に等しいコメントが作成されます。
私はどこから始めればいいのか少し行き詰まっています。これは、継承されたリソースの適切な使用例ですか?
class CommentsController < InheritedResources::Base
respond_to :js, :only => :create
belongs_to :article, :cheat, :gallery, :video, :polymorphic => true
do
belongs_to :comments
end
def create
create! do |format|
# How in here do I build a comment so that it handles
polymorphism?
@comment.children.create(:commentable => @article or @cheat or
@something_generic?)
end
end
end