I'm watching a RailsCast on polymorphic associations. http://railscasts.com/episodes/154-polymorphic-association?view=asciicast
There's three different models Article, Photo and Event that each take a comment from Comment.rb. (Article, Photo and Event each of a article_id, photo_id, and event_id). In listing the comments he has the problem of figuring out which of the 3 models to list the comments for, so he does this in the index action
def index
@commentable = find_commentable
@comments = @commentable.comments
end
def find_commentable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
My question is, what is $1
?