PolyPath
PolyPath is a helper for use in your controllers and views for specifying paths to nested polymorphic resources.
Example:
if you have the following three models:1 class User < ActiveRecord::Base 2 has_many :photos, :as => :photoable 3 end 4 5 class Event < ActiveRecord::Base 6 has_many :photos, :as => :photoable 7 end 8 9 class Photo < ActiveRecord::Base 10 belongs :to => :photoable, :polymorphic => true 11 end
1 map.resources :photos, :path_prefix => "/:photoable_type/:photoable_id"
1 photo_url(poly_path(photo, :photoable))
There are currenltly no tests for this plugin as it was a five minute proof of concept. If there is interest, there are plenty of improvments that can be made.
- Repository Path: http://smarticus.googlecode.com/svn/trunk/plugins/poly_path/
- Homepage: http://smartic.us/