Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require File.expand_path('../../config/boot', __FILE__)
- require File.expand_path('../../config/environment', __FILE__)
- require 'erb'
- Dir["../app/models/*.rb"].each do |file_path|
- #require file_path # Make sure that the model has been loaded.
- @controller = ERB.new(%q{
- class <%= model_name.pluralize %>Controller < ApplicationController
- def initialize
- @model_name = '<%= model_name %>'
- @index_field = [<%= index_fields %>]
- @edit_field = [<%= edit_fields %>]
- end
- end
- }, 0, "%<>")
- basename = File.basename(file_path, File.extname(file_path))
- @model_name = basename.camelize
- @model = @model_name.constantize
- @fields = @model.columns.map { |x| x.name }
- @index_fields = @fields.map { |x| "'#{x}'" }.join(',')
- ["id","create_dt","update_dt"].each { |x| @fields.delete(x) }
- @edit_fields = @fields.map { |x| "'#{x}'" }.join(',')
- puts @controller.result(binding())
- end
Add Comment
Please, Sign In to add comment