RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: AlainPilon
Site: www.canon5dtips.com
RABL gets pretty cryptic as soon as you start returning complex JSON which is why I moved to jbuilder and while it served me well so far, AMS seems to offer a better structure and I plan to use it for my next project.
I still dont agree with your pattern. What happen when you have a nested article - picture - comment?
Your technique will see the article_id and load it as the commentable while we are trying to comment on the picture.
That being said, I agree that being able to add scopes is a plus and I find that it is your biggest argument.
Adrian: look at the solution I describe above. Way less verbose than yours and more flexible.
Ryan: to get the type of commentable tpye and ID, I use the follow code:
def get_commentable @commentable = params[:commentable].classify.constantize.find(commentable_id) end def commentable_id params[(params[:commentable].singularize + "_id").to_sym] end
and append to the nested comment resource this
, :defaults => { :commentable => 'picture' }
(when commenting on picture)
This way, the only thing you have to remember when adding more commentable is to add the default param to the route and you are done ;-)
RABL gets pretty cryptic as soon as you start returning complex JSON which is why I moved to jbuilder and while it served me well so far, AMS seems to offer a better structure and I plan to use it for my next project.
I still dont agree with your pattern. What happen when you have a nested article - picture - comment?
Your technique will see the article_id and load it as the commentable while we are trying to comment on the picture.
That being said, I agree that being able to add scopes is a plus and I find that it is your biggest argument.
Adrian: look at the solution I describe above. Way less verbose than yours and more flexible.
Ryan: to get the type of commentable tpye and ID, I use the follow code:
and append to the nested comment resource this
, :defaults => { :commentable => 'picture' }
(when commenting on picture)
This way, the only thing you have to remember when adding more commentable is to add the default param to the route and you are done ;-)