Class: AddSlugToStories

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/branston/db/migrate/20091204173634_add_slug_to_stories.rb

Class Method Summary collapse

Class Method Details

.downObject



10
11
12
# File 'lib/branston/db/migrate/20091204173634_add_slug_to_stories.rb', line 10

def self.down
  remove_column :stories, :slug
end

.upObject



2
3
4
5
6
7
8
# File 'lib/branston/db/migrate/20091204173634_add_slug_to_stories.rb', line 2

def self.up
  add_column :stories, :slug, :string, :null => false, :default => ''
  Story.all.each do |story|
    story.slug = story.title.parameterize
    story.save!
  end
end