RailsCasts Pro episodes are now free!

Learn more or hide this

Alain Pilon's Profile

GitHub User: AlainPilon

Site: www.canon5dtips.com

Comments by Alain Pilon

Avatar

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.

Avatar

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.

Avatar

Adrian: look at the solution I describe above. Way less verbose than yours and more flexible.

Avatar

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 ;-)