class SocialEngine::Engine
Public Class Methods
add_poly_belongs_to()
click to toggle source
TODO:refactor add polymorhpic_belongs_to to inherited_resources controllers after detecting which models use 'able' functions
# File lib/social_engine/engine.rb, line 30 def self.add_poly_belongs_to [CommentsController,RatingsController,VotesController,FavoritesController].each do |controller| poly_belongs_tos = [] Dir.glob("#{Rails.root.to_s}/app/models/**/*.rb").each do |model_name| #TODO: gotta be a better way to do this. REFACTOR! model_name = model_name.split("/").last.gsub(".rb","") klass = model_name.camelize.constantize rescue next able_id = controller.to_s.gsub("sController","").gsub("ing","e").downcase+"able?" poly_belongs_tos << model_name.to_sym if klass.instance_methods.include?(able_id.to_sym) end controller.class_eval("polymorphic_belongs_to :#{poly_belongs_tos.join(',:')}") unless poly_belongs_tos.blank? end end