RailsCasts Pro episodes are now free!

Learn more or hide this

aurelplouf's Profile

GitHub User: aurelplouf

Comments by


Hello I learned a lot from this episode about Polymorphic association, which always seemed a bit mysterious!

I think what the episode is really missing, is an explanation about polymorphic_url or polymorphic_path in order to recognize which model you wish to redirect. It is extremely helpful to understand this method especially when nesting multiple polymorphic models (see documentation). For example

def update
     @comment = Comment.find(params[:id])
     response_to do |format|
         format.html do
               if @comment.errors.present?
                     render :edit
                     redirect_to polymorphic_path(@commentable), :notice => "Yay updated!"
                     # or
                     # redirect_to polymorphic_path([@commentable, @comment]), :notice => "Yay i can update and see further down the path!"

sorry if messed up the comment markup ^^

Thank you Ryan for the wonderful videos. I have been watching your masterpieces for a few years. I love your Pro and Revised versions, Keep it up!