Class: CreateAdminpanelTables
- Inherits:
-
ActiveRecord::Migration
- Object
- ActiveRecord::Migration
- CreateAdminpanelTables
- Defined in:
- lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb
Instance Method Summary collapse
Instance Method Details
#change ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb', line 21 def change create_table :adminpanel_users do |t| t.string :name t.string :email t.string :password_digest t.string :remember_token t. end add_index :adminpanel_users, [:email] add_index :adminpanel_users, [:remember_token] create_table :adminpanel_galleries do |t| t.string :file t.integer :position t. end create_table :adminpanel_images do |t| t.string :file t.integer :foreign_key t.string :model t. end create_table :adminpanel_sections do |t| t.string :name t.boolean :has_description t.text :description t.string :key t.string :page t.boolean :has_image t. end add_index :adminpanel_sections, [:key] end |
#migrate(direction) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/adminpanel/initialize/templates/create_adminpanel_tables.rb', line 2 def migrate(direction) super # Create a default user if direction == :up if Rails.env.development? Adminpanel::User.new(:email => '[email protected]', :name => "Admin", :password => 'password', :password_confirmation => 'password').save puts "The password for [email protected] is: password" else characters = ("a".."z").to_a << ("A".."Z").to_a << (0..9).to_a <<(["!","@","#","$","%","^","&","*","(",")", "_", "-","+", "="]) password = "" 8.times do password = password + "#{characters.sample}" end puts "The password for [email protected] is: #{password}" Adminpanel::User.new(:email => "[email protected]", :name => "Admin", :password => password, :password_confirmation => password).save end end end |