How to create a Database Table in a Controller


Unfortunately, you won't be able to use a mixin to access the methods
that you want to actually create the database table. The create_table
method can only be accessed through classes that inherit

I would suggest creating another class that inherits
ActiveRecord::Migration and then setup some methods to set all of the
attributes of the table. Once you've set that up then you can call
the migrate method of the class and it will update the database.

# In controller
class TableController < ApplicationController
  def create
    @results = CreateUsers.migrate(:up)

  class CreateUsers < ActiveRecord::Migration
    def self.up
      create_table ....

    def self.down
      drop_table ....

Now if you're managing your database using migrations, I would not
recommend updating the database inside the controller unless you save
the migration to the filesystem and manage the versioning on the
schema_info table.

Hope this helps.