You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
I have a Comment model which belongs_to :commentable, polymorphic: true association. I'm wondeirng how to setup the controller, here's what I have to far:
classCommentsController < APIControllerbefore_action:load_commentableload_and_authorize_resource:through=>:commentable# GET .../commentsdefindex@comments=@commentable.commentsend# GET .../comments/:iddefshow@comment=@commentable.comments.find(params[:id])end# POST .../commentsdefcreate@comment=@commentable.comments.build(comment_params)if@comment.save# ...else# ...endend# PATCH .../comments/:iddefupdate@comment=@commentable.comments.find(params[:id])if@comment.update(comment_params)# ...else# ...endend# DELETE .../comments/:iddefdestroy@comment=@commentable.comments.find(params[:id])@comment.destroy# ...endprivatedefcomment_params# ...enddefload_commentableparams.eachdo |name,value|
ifname =~ /(.+)_id$/@commentable= $1.classify.constantize.find(value)endendendend
The text was updated successfully, but these errors were encountered:
I have a Comment model which
belongs_to :commentable, polymorphic: true
association. I'm wondeirng how to setup the controller, here's what I have to far:The text was updated successfully, but these errors were encountered: