I\'m creating a Rails gem that integrates closely with Active Record. The gem requires a number of fields to be defined. For example:
class User < ActiveRecor
Actually if you call
rails g model profile name:string next:attached
rails allready generates you a migration with
def self.up
create_table :profiles do |t|
t.string :name
t.attached :next
t.timestamps
end
end
however you can override the default migration template by placing it in /lib/templates/active_record/model/migration.rb
You should write a rake my_gem:setup task to put the file there I haven't tried, but i guess rails does not search in non-engine gems for these templates
Your migration template contents would then look like
class <%= migration_class_name %> < ActiveRecord::Migration
def self.up
create_table :<%= table_name %> do |t|
<% for attribute in attributes -%>
<% if attribute.type.to_s == "attached" %>
t.string :<%= attribute.name %>_identifier
t.string :<%= attribute.name %>_extension
t.integer :<%= attribute.name %>_size
<% else %>
t.<%= attribute.type %> :<%= attribute.name %>
<% end %>
<% end -%>
<% if options[:timestamps] %>
t.timestamps
<% end -%>
end
end
def self.down
drop_table :<%= table_name %>
end
end