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 < ActiveRecord::Base
# requires 'avatar_identifier', 'avatar_extension', 'avatar_size'
has_attached :avatar
end
Is it possible to have something like:
rails g model user name:string avatar:attached
Resulting in:
create_table :users do |t|
t.string :name
t.string :avatar_identifier
t.string :avatar_extension
t.integer :avatar_size
end
If this isn’t possible, any way to make:
create_table :users do |t|
t.string :name
t.attached :avatar
end
Generate multiple fields? Thanks!
While Pravin did point in the right direction, i found it was not straightforward to implement it. I did the following, i added a file in
config/initializers(name is not relevant), containing the following:then you can just do something like:
which will create the following migration:
If you then run the migration,
rake db:migrateit will create the followingPersonmodel:Hope this helps!!