ruby on rails - Using inherited_resources for nested, polymorphic comments -


i new using inherited resources , want use polymorphic nested comments. have several objects commentable (articles, galleries, etc.) , comments can nested. i'm using combination of awesome_nested_set (parent_id, lft, rgt) comment model having polymorphic commentable columns.

the controller needs receive ajax request (only) create action , perform below:

posting /articles/12/comments/34 creates comment commentable equal @article (12) , parent equal @comment (34)

/articles/12/comments/34

posting /gallery/12/comments/34 creates comment commentable equal @gallery (12) , parent equal @comment (34)

i'm bit stuck on begin. use case inherited resources?


class commentscontroller < inheritedresources::base    respond_to :js, :only => :create    belongs_to :article, :cheat, :gallery, :video, :polymorphic => true       belongs_to :comments    end    def create      create! |format|         # how in here build comment handles  polymorphism?         @comment.children.create(:commentable => @article or @cheat or  @something_generic?)      end    end  end  

nested comments difficult. rails resources don't provide in passing id create action, don't think can post create action way. might need add comment belong_to options, can post /comments/33/comments. don't know if inheritedresources support this. if does, object creation should automatic. can reference stuff parent_url too.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -