Frage

How to create migration to add the admin field to the users table with a boolean value and set default to false in Sinatra? I am using Active Record.

War es hilfreich?

Lösung

It's still just ActiveRecord, this would be no different than using it in Rails.

class AddAdminToUsers < ActiveRecord::Migration
  def change
    add_column :admin, :boolean, :default => false
  end
end

You may also want to check out the sinatra-activerecord gem which will give you some extra rake tasks and makes things a little easier.

Here is also a useful article on using Sinatra with ActiveRecord.

Sinatra and ActiveRecord

Andere Tipps

I was having this problem too.

I solved it using change_table method instead of add_column so final code would look like:

class AddAdminToUsers < ActiveRecord::Migration
  def change
    change_table :users do |t|
      t.column :admin, :boolean, default: false
    end
  end
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top