Courtesy of Twitter

I am so freaking awesome

  (Dir.entries("#{RAILS_ROOT}/app/models") - [".","..",".svn"]).each do |model|
    has_many model.split(".").first.pluralize.to_sym, :foreign_key => "owner_id"
  end

I tried adding:

 if model.classify.is_a?(ActiveRecord::Base)
      <<-EVAL
      class #{model.classify}
        belongs_to :owner
      end
      EVAL
    end

too, but Rails didn’t like that.

2 Responses to “I am so freaking awesome”

  1. Sutto Says:

    Are you actually eval’ing the second one though? looks like you’re just getting a string for it.

  2. Radar Says:

    D’oh! I should’ve called eval! Silly me. Thanks Sutto. I’ve abandoned that eval’ing path and just took the longer road by adding belongs_to :owner to all other models.

Leave a Reply