public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Rejiggered migrations to get preference creation to work
Michael Hartl (author)
Wed Apr 23 10:59:08 -0700 2008
commit  a4f77491798216416e5f0259cb49d659c8497864
tree    42bdb4b79d97b9fce4ededfe6343a3704309baad
parent  bfccce2f990f963bfd062ada580fac1c37b67d7b
...
19
20
21
22
23
24
25
26
27
28
29
...
19
20
21
 
 
 
 
 
22
23
24
0
@@ -19,11 +19,6 @@ class Preference < ActiveRecord::Base
0
   validates_presence_of :domain, :if => :using_email?
0
   validates_presence_of :smtp_server, :if => :using_email?
0
   
0
- # Make the text fields blank instead of nil.
0
- after_initialize do
0
- self.analytics = ""
0
- end
0
-
0
   private
0
   
0
     def using_email?
...
1
2
3
4
...
12
13
14
 
 
15
16
17
...
 
1
2
3
...
11
12
13
14
15
16
17
18
0
@@ -1,4 +1,3 @@
0
-# Rescue from the error raised upon first migrating.
0
 begin
0
   unless test?
0
     global_prefs = Preference.find(:first)
0
@@ -12,5 +11,7 @@ begin
0
     end
0
   end
0
 rescue
0
+ # Rescue from the error raised upon first migrating
0
+ # (needed to bootstrap the preferences).
0
   nil
0
 end
0
\ No newline at end of file
...
1
2
 
3
4
5
6
7
8
 
9
10
11
12
13
14
...
1
2
3
4
5
6
7
8
 
9
10
11
 
12
13
14
0
@@ -1,14 +1,14 @@
0
 class CreatePreferences < ActiveRecord::Migration
0
   def self.up
0
+ # drop_table :preferences rescue nil
0
     create_table :preferences do |t|
0
       t.string :domain, :null => false, :default => ""
0
       t.string :smtp_server, :null => false, :default => ""
0
       t.boolean :email_notifications, :null => false, :default => false
0
       t.boolean :email_verifications, :null => false, :default => false
0
-
0
+
0
       t.timestamps
0
     end
0
- Preference.create!
0
   end
0
 
0
   def self.down
...
1
2
3
 
4
5
6
...
1
2
3
4
5
6
7
0
@@ -1,6 +1,7 @@
0
 class AddAnalyticsPreference < ActiveRecord::Migration
0
   def self.up
0
     add_column :preferences, :analytics, :text
0
+ Preference.create! if Preference.count.zero?
0
   end
0
 
0
   def self.down

Comments

    No one has commented yet.