09 Mar '12, 10pm

Railscasts - Polymorphic Association:

class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end class Article < ActiveRecord::Base has_many :comments, :as => :commentable end class Photo < ActiveRecord::Base has_many :comments, :as => :commentable #... end class Event < ActiveRecord::Base has_many :comments, :as => :commentable end # comments_controller def index @commentable = find_commentable @comments = @commentable.comments end def create @commentable = find_commentable @comment = @commentable.comments.build(params[:comment]) if @comment.save flash[:notice] = "Successfully created comment." redirect_to :id => nil else render :action => 'new' end end private def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value) end end nil end

Full article: http://railscasts.com/episodes/154-polymorphic-association

Tweets

#154 Polymorphic Association - RailsCasts:

railscasts.com 15 Mar '12, 5pm

class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end class Article < ActiveRecord::Base ha...

Railscasts - Auto-Complete Association:

railscasts.com 07 Mar '12, 2am

Usually a select menu is used for setting a belongs_to association, but in this episode I will show you how to use a text ...

Revolution On Rails: DRYing Up Polymorphic Controllers:

Revolution On Rails: DRYing Up Polymorphic Cont...

Polymorphic routes allow drying up the controller implementation when functionality is identical, regardless of entry poin...

@Moxy_Tod In anticipation of tomorrow's trip to the Eurasian Association, did some reading and stumbled across this:

@Moxy_Tod In anticipation of tomorrow's trip to...

is.asia-city.com 09 Mar '12, 8am

Take a walk down any street and you’ll see a kaleidoscope of faces—of numerous races—greeting you. Yet, when visitors (and...

@KARLcabbyJAMES

lvta.co.uk 12 Mar '12, 9pm

Perhaps the best-remembered cab is the Austin FX3, many thousands of these were built for London service in the 1950s. Wel...