047_add_content_state_field.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. class AddContentStateField < ActiveRecord::Migration
  2.   class Content < ActiveRecord::Base
  3.     include BareMigration
  4.   end
  5.   def self.up
  6.     modify_tables_and_update(:add_column, Content,
  7.                              :state, :text) do |content|
  8.       unless $schema_generator
  9.         if content.published?
  10.           content.state = 'Published'
  11.         elsif content.published_at
  12.           content.state = 'PublicationPending'
  13.         else
  14.           content.state = 'Draft'
  15.         end
  16.       end
  17.     end
  18.   end
  19.   def self.down
  20.     remove_column :contents, :state
  21.   end
  22. end