Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

aurelplouf's Profile

GitHub User: aurelplouf

Comments by

Avatar

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

ruby
def update
     @comment = Comment.find(params[:id])
     @comment.update_attributes(params[:comment])
     response_to do |format|
         format.html do
               if @comment.errors.present?
                     render :edit
               else
                     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!"
               end
         end
     end
end

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!