문제

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