mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-12 18:34:22 +01:00
add state machine to context including a closed state
This commit is contained in:
parent
3c6b1737c1
commit
99eed9f638
4 changed files with 93 additions and 28 deletions
22
db/migrate/20130227205845_add_state_to_context.rb
Normal file
22
db/migrate/20130227205845_add_state_to_context.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class AddStateToContext < ActiveRecord::Migration
|
||||
|
||||
class Context < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
add_column :contexts, :state, :string, :limit => 20, :null => false
|
||||
Context.reset_column_information
|
||||
Context.all.each do |c|
|
||||
c.state = c.hide ? 'hidden' : 'active'
|
||||
c.save!
|
||||
end
|
||||
remove_column :contexts, :hide
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :contexts, :hide, :boolean, :default => false
|
||||
Context.reset_column_information
|
||||
Context.all.each { |c| c.hide = ( c.state == 'hidden' ) }
|
||||
remove_column :contexts, :state
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue