Created
          June 11, 2014 04:05 
        
      - 
      
- 
        Save Catharz/fe237dc5e1d19936627b to your computer and use it in GitHub Desktop. 
    Create Rails models for every table in the database
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | invalid_chars = [' ', '$', '(', ')'] | |
| ActiveRecord::Base.connection.tables.each do |table_name| | |
| name = table_name | |
| invalid_chars.map { |ch| name = name.gsub(ch, '_') } | |
| name = name.camelize | |
| name = name + "_" if Module.const_defined? name | |
| eval %{ | |
| class #{name} < ActiveRecord::Base | |
| self.table_name = "#{table_name}" ; | |
| self.primary_key = "#{ActiveRecord::Base.connection.primary_key table_name}" ; | |
| end | |
| } | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment