Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require File.expand_path('../../config/boot', __FILE__)
  3. require File.expand_path('../../config/environment', __FILE__)
  4. require 'erb'
  5.  
  6. Dir["../app/models/*.rb"].each do |file_path|
  7. #require file_path # Make sure that the model has been loaded.
  8.  
  9. @controller = ERB.new(%q{
  10. class <%= model_name.pluralize %>Controller < ApplicationController
  11. def initialize
  12. @model_name = '<%= model_name %>'
  13. @index_field = [<%= index_fields %>]
  14. @edit_field = [<%= edit_fields %>]
  15. end
  16. end
  17. }, 0, "%<>")
  18.  
  19. basename = File.basename(file_path, File.extname(file_path))
  20. @model_name = basename.camelize
  21. @model = @model_name.constantize
  22. @fields = @model.columns.map { |x| x.name }
  23. @index_fields = @fields.map { |x| "'#{x}'" }.join(',')
  24. ["id","create_dt","update_dt"].each { |x| @fields.delete(x) }
  25. @edit_fields = @fields.map { |x| "'#{x}'" }.join(',')
  26.  
  27. puts @controller.result
  28. end
Add Comment
Please, Sign In to add comment