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.

有帮助吗?

解决方案

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

其他提示

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top