public
Description: El Dorado is a full-stack community web application written in Ruby/Rails.
Homepage: http://almosteffortless.com/eldorado/
Clone URL: git://github.com/trevorturk/el-dorado.git
fixing login/logout double_redirect errors, proactivevely checking for 
similar issues, moving default settings into model, annotating models

git-svn-id: http://eldorado.googlecode.com/svn/trunk@633 
9c008b19-a030-0410-9975-d76d301b4276
trevorturk (author)
Thu Jan 24 19:23:57 -0800 2008
commit  f9a1c11025bd5e63461dbc7269b93e8b9e5f2251
tree    3b93f8e19d3a9d28028a25f11c1c9afa672a68f5
parent  cea57e058ac3453c43dd4d781edd331903fc1c67
...
24
25
26
27
28
 
29
30
31
...
24
25
26
 
 
27
28
29
30
0
@@ -24,8 +24,7 @@ class ApplicationController < ActionController::Base
0
   def get_settings
0
     @settings ||= Setting.find(:first)
0
     if @settings.nil?
0
- @settings = Setting.new(:title => 'El Dorado', :tagline => 'All an elaborate, unapproachable, unprofitable, retributive joke', :footer => '<p style="text-align:right;margin:0;">Powered by El Dorado | <a href="http://almosteffortless.com">&aelig;</a></p>')
0
- @settings.save!
0
+ @settings = Setting.defaults
0
       flash[:notice] = 'Welcome to El Dorado! Please create a new user account for yourself.'
0
       redirect_to new_user_path
0
     end
...
17
18
19
20
 
21
22
23
...
17
18
19
 
20
21
22
23
0
@@ -17,7 +17,7 @@ class PostsController < ApplicationController
0
 
0
   def create
0
     @topic = Topic.find(params[:post][:topic_id])
0
- redirect_home unless @topic
0
+ redirect_to root_path and return false unless @topic
0
     @post = current_user.posts.build(params[:post])
0
     if @topic.locked
0
       redirect_to root_path and return false unless admin? || (current_user == @topic.user)
...
27
28
29
30
 
31
32
33
...
27
28
29
 
30
31
32
33
0
@@ -27,7 +27,7 @@ class TopicsController < ApplicationController
0
   def create
0
     @topic = current_user.topics.build(params[:topic])
0
     @post = @topic.posts.build(params[:topic]) ; @post.user = current_user
0
- redirect_to @topic and return if @topic.save && @post.save
0
+ redirect_to @topic and return true if @topic.save && @post.save
0
     render :action => "new"
0
   end
0
   
...
18
19
20
21
 
22
23
 
24
25
26
...
67
68
69
70
 
71
72
73
...
80
81
82
83
 
84
85
86
...
18
19
20
 
21
22
 
23
24
25
26
...
67
68
69
 
70
71
72
73
...
80
81
82
 
83
84
85
86
0
@@ -18,9 +18,9 @@ class UsersController < ApplicationController
0
   def create
0
     @user = User.new(params[:user])
0
     @user.admin = true if User.count == 0
0
- render :action => :new and return unless @user.save
0
+ render :action => :new and return false unless @user.save
0
     if logged_in?
0
- redirect_to users_path and return
0
+ redirect_to users_path and return true
0
     else
0
       do_login(@user)
0
     end
0
@@ -67,7 +67,7 @@ class UsersController < ApplicationController
0
   end
0
   
0
   def login
0
- redirect_to root_path if logged_in?
0
+ redirect_to root_path and return false if logged_in?
0
     if request.post?
0
       @user = User.authenticate(params[:user][:login], params[:user][:password]) unless params[:user].blank?
0
       if @user
0
@@ -80,7 +80,7 @@ class UsersController < ApplicationController
0
   end
0
   
0
   def logout
0
- redirect_home unless logged_in?
0
+ redirect_to root_path and return false unless logged_in?
0
     @flash = flash[:notice]
0
     @user = User.find_by_id(session[:user_id])
0
     if @user
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
14
15
 
 
 
 
 
16
17
18
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
 
 
11
12
13
14
15
16
17
18
0
@@ -1,18 +1,18 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: avatars
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
-# user_id :integer(11)
0
-# current_user_id :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
+# user_id :integer
0
+# current_user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
 #
...
1
2
 
3
4
5
6
 
7
8
 
9
10
11
...
1
 
2
3
4
5
 
6
7
 
8
9
10
11
0
@@ -1,11 +1,11 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: categories
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # name :string(255)
0
-# position :integer(11) default(0)
0
+# position :integer default(0)
0
 #
0
 
0
 class Category < ActiveRecord::Base
...
1
2
 
3
4
5
6
 
7
8
9
10
11
12
 
 
 
13
14
15
...
1
 
2
3
4
5
 
6
7
8
9
 
 
 
10
11
12
13
14
15
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: events
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # title :string(255)
0
 # description :text
0
 # date :datetime
0
-# private :boolean(1)
0
-# reminder :boolean(1)
0
-# user_id :integer(11)
0
+# private :boolean
0
+# reminder :boolean
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
 #
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
 
 
 
13
14
15
...
1
 
2
3
4
5
 
 
6
7
8
9
 
 
 
10
11
12
13
14
15
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: forums
0
 #
0
-# id :integer(11) not null, primary key
0
-# category_id :integer(11)
0
+# id :integer not null, primary key
0
+# category_id :integer
0
 # name :string(255)
0
 # description :text
0
-# topics_count :integer(11) default(0)
0
-# posts_count :integer(11) default(0)
0
-# position :integer(11) default(0)
0
+# topics_count :integer default(0)
0
+# posts_count :integer default(0)
0
+# position :integer default(0)
0
 #
0
 
0
 class Forum < ActiveRecord::Base
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
 
 
 
14
15
 
16
17
18
 
19
20
21
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
11
12
13
14
 
15
16
17
 
18
19
20
21
0
@@ -1,21 +1,21 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: headers
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
 # description :text
0
-# user_id :integer(11)
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
-# votes :integer(11) default(0)
0
+# votes :integer default(0)
0
 #
0
 
0
 class Header < ActiveRecord::Base
...
1
2
 
3
4
5
6
7
8
 
 
 
9
10
11
12
 
13
14
15
...
1
 
2
3
4
5
 
 
 
6
7
8
9
10
11
 
12
13
14
15
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: posts
0
 #
0
-# id :integer(11) not null, primary key
0
-# user_id :integer(11)
0
-# topic_id :integer(11)
0
+# id :integer not null, primary key
0
+# user_id :integer
0
+# topic_id :integer
0
 # body :text
0
 # created_at :datetime
0
 # updated_at :datetime
0
-# updated_by :integer(11)
0
+# updated_by :integer
0
 #
0
 
0
 class Post < ActiveRecord::Base
...
1
2
 
3
4
5
6
 
7
8
 
9
10
11
...
1
 
2
3
4
5
 
6
7
 
8
9
10
11
0
@@ -1,11 +1,11 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: ranks
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # title :string(255)
0
-# min_posts :integer(11)
0
+# min_posts :integer
0
 #
0
 
0
 class Rank < ActiveRecord::Base
...
1
2
 
3
4
5
6
 
7
8
9
...
19
20
21
 
 
 
 
22
23
24
25
 
 
 
 
 
 
26
27
28
...
1
 
2
3
4
5
 
6
7
8
9
...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -1,9 +1,9 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: settings
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # title :string(255)
0
 # tagline :string(255)
0
 # announcement :text
0
@@ -19,10 +19,20 @@ class Setting < ActiveRecord::Base
0
   
0
   composed_of :tz, :class_name => 'TZInfo::Timezone', :mapping => %w( time_zone time_zone )
0
   
0
+ DEFAULT_TITLE = 'El Dorado'
0
+ DEFAULT_TAGLINE = 'A full-stack community web application written in Ruby/Rails'
0
+ DEFAULT_FOOTER = '<p style="text-align:right;margin:0;">Powered by El Dorado | <a href="http://almosteffortless.com">&aelig;</a></p>'
0
+
0
   def theme
0
     read_attribute(:theme) # not sure why this is needed, but tests are failing without it
0
   end
0
   
0
+ def self.defaults
0
+ @settings = Setting.new(:title => DEFAULT_TITLE, :tagline => DEFAULT_TAGLINE, :footer => DEFAULT_FOOTER)
0
+ @settings.save
0
+ @settings
0
+ end
0
+
0
   def to_s
0
     title.to_s
0
   end
...
1
2
 
3
4
5
6
7
8
 
 
 
9
10
11
...
1
 
2
3
4
5
 
 
 
6
7
8
9
10
11
0
@@ -1,11 +1,11 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: subscriptions
0
 #
0
-# id :integer(11) not null, primary key
0
-# user_id :integer(11)
0
-# topic_id :integer(11)
0
+# id :integer not null, primary key
0
+# user_id :integer
0
+# topic_id :integer
0
 #
0
 
0
 class Subscription < ActiveRecord::Base
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
14
 
 
 
 
15
16
17
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
 
11
12
13
14
15
16
17
0
@@ -1,17 +1,17 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: themes
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
-# user_id :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
 #
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
 
 
 
13
14
15
16
17
18
 
 
 
 
 
19
20
21
...
1
 
2
3
4
5
 
 
6
7
8
9
 
 
 
10
11
12
13
 
 
 
 
 
14
15
16
17
18
19
20
21
0
@@ -1,21 +1,21 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: topics
0
 #
0
-# id :integer(11) not null, primary key
0
-# user_id :integer(11)
0
+# id :integer not null, primary key
0
+# user_id :integer
0
 # title :string(255)
0
 # created_at :datetime
0
-# views :integer(11) default(0)
0
-# posts_count :integer(11) default(0)
0
-# last_post_id :integer(11)
0
+# views :integer default(0)
0
+# posts_count :integer default(0)
0
+# last_post_id :integer
0
 # last_post_at :datetime
0
-# last_post_by :integer(11)
0
-# private :boolean(1)
0
-# locked :boolean(1)
0
-# sticky :boolean(1)
0
-# forum_id :integer(11)
0
+# last_post_by :integer
0
+# private :boolean
0
+# locked :boolean
0
+# sticky :boolean
0
+# forum_id :integer
0
 #
0
 
0
 class Topic < ActiveRecord::Base
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
14
 
 
 
 
15
16
17
 
18
19
20
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
 
11
12
13
14
15
16
 
17
18
19
20
0
@@ -1,20 +1,20 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: uploads
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
-# user_id :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
-# private :boolean(1)
0
+# private :boolean
0
 #
0
 
0
 class Upload < ActiveRecord::Base
...
1
2
 
3
4
5
6
 
7
8
9
10
11
12
 
 
13
14
15
...
18
19
20
 
 
21
22
23
...
1
 
2
3
4
5
 
6
7
8
9
10
 
 
11
12
13
14
15
...
18
19
20
21
22
23
24
25
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: users
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # login :string(255)
0
 # email :string(255)
0
 # password_hash :string(255)
0
 # created_at :datetime
0
-# admin :boolean(1)
0
-# posts_count :integer(11) default(0)
0
+# admin :boolean
0
+# posts_count :integer default(0)
0
 # signature :string(255)
0
 # bio :text
0
 # profile_updated_at :datetime
0
@@ -18,6 +18,8 @@
0
 # auth_token :string(255)
0
 # auth_token_exp :datetime
0
 # time_zone :string(255)
0
+# ban_message :string(255)
0
+# banned_until :datetime
0
 #
0
 
0
 require 'digest/sha1'
...
52
53
54
55
56
 
57
58
59
...
90
91
92
93
94
 
95
96
97
...
141
142
143
144
145
 
146
147
148
...
52
53
54
 
55
56
57
58
59
...
90
91
92
 
93
94
95
96
97
...
141
142
143
 
144
145
146
147
148
0
@@ -52,8 +52,8 @@ ActiveRecord::Schema.define(:version => 68) do
0
     t.integer "position", :default => 0
0
   end
0
 
0
- add_index "forums", ["category_id"], :name => "index_forums_on_category_id"
0
   add_index "forums", ["category_id"], :name => "index_forums_on_last_post_at"
0
+ add_index "forums", ["category_id"], :name => "index_forums_on_category_id"
0
 
0
   create_table "headers", :force => true do |t|
0
     t.integer "parent_id"
0
@@ -90,8 +90,8 @@ ActiveRecord::Schema.define(:version => 68) do
0
     t.integer "updated_by"
0
   end
0
 
0
- add_index "posts", ["topic_id"], :name => "index_posts_on_topic_id"
0
   add_index "posts", ["user_id", "created_at"], :name => "index_posts_on_user_id"
0
+ add_index "posts", ["topic_id"], :name => "index_posts_on_topic_id"
0
 
0
   create_table "ranks", :force => true do |t|
0
     t.string "title"
0
@@ -141,8 +141,8 @@ ActiveRecord::Schema.define(:version => 68) do
0
     t.integer "forum_id"
0
   end
0
 
0
- add_index "topics", ["forum_id"], :name => "index_topics_on_forum_id"
0
   add_index "topics", ["forum_id", "last_post_at"], :name => "index_topics_on_last_post_at"
0
+ add_index "topics", ["forum_id"], :name => "index_topics_on_forum_id"
0
 
0
   create_table "uploads", :force => true do |t|
0
     t.integer "parent_id"
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
14
15
 
 
 
 
 
16
17
18
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
 
 
11
12
13
14
15
16
17
18
0
@@ -1,18 +1,18 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: avatars
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
-# user_id :integer(11)
0
-# current_user_id :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
+# user_id :integer
0
+# current_user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
 #
...
1
2
 
3
4
5
6
 
7
8
 
9
10
11
...
18
19
20
21
22
 
...
1
 
2
3
4
5
 
6
7
 
8
9
10
11
...
18
19
20
 
21
22
0
@@ -1,11 +1,11 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: categories
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # name :string(255)
0
-# position :integer(11) default(0)
0
+# position :integer default(0)
0
 #
0
 
0
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
0
@@ -18,4 +18,4 @@ two:
0
   name: 'second category'
0
   position: '0'
0
 deleteme:
0
- name: deleteme
0
\ No newline at end of file
0
+ name: deleteme
...
1
2
 
3
4
5
6
 
7
8
9
10
11
12
 
 
 
13
14
15
...
1
 
2
3
4
5
 
6
7
8
9
 
 
 
10
11
12
13
14
15
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: events
0
 #
0
-# id :integer(11) not null, primary key
0
+# id :integer not null, primary key
0
 # title :string(255)
0
 # description :text
0
 # date :datetime
0
-# private :boolean(1)
0
-# reminder :boolean(1)
0
-# user_id :integer(11)
0
+# private :boolean
0
+# reminder :boolean
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
 #
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
 
 
 
13
14
15
...
1
 
2
3
4
5
 
 
6
7
8
9
 
 
 
10
11
12
13
14
15
0
@@ -1,15 +1,15 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: forums
0
 #
0
-# id :integer(11) not null, primary key
0
-# category_id :integer(11)
0
+# id :integer not null, primary key
0
+# category_id :integer
0
 # name :string(255)
0
 # description :text
0
-# topics_count :integer(11) default(0)
0
-# posts_count :integer(11) default(0)
0
-# position :integer(11) default(0)
0
+# topics_count :integer default(0)
0
+# posts_count :integer default(0)
0
+# position :integer default(0)
0
 #
0
 
0
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
...
1
2
 
3
4
5
6
7
 
 
8
9
10
11
12
13
 
 
 
14
15
 
16
17
18
 
19
20
21
...
1
 
2
3
4
5
 
 
6
7
8
9
10
 
 
 
11
12
13
14
 
15
16
17
 
18
19
20
21
0
@@ -1,21 +1,21 @@
0
 # == Schema Information
0
-# Schema version: 67
0
+# Schema version: 68
0
 #
0
 # Table name: headers
0
 #
0
-# id :integer(11) not null, primary key
0
-# parent_id :integer(11)
0
+# id :integer not null, primary key
0
+# parent_id :integer
0
 # content_type :string(255)
0
 # filename :string(255)
0
 # thumbnail :string(255)
0
-# size :integer(11)
0
-# width :integer(11)
0
-# height :integer(11)
0
+# size :integer
0
+# width :integer
0
+# height :integer
0
 # description :text
0
-# user_id :integer(11)
0
+# user_id :integer
0
 # created_at :datetime
0
 # updated_at :datetime
0
-# votes :integer(11) default(0)
0
+# votes :integer default(0)
0
 #
0
 
0
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
...
1
2
 
3
4
5
6
7
8
 
 
 
9
10
11
12
 
13
14
15
...
53
54
55
56
57
 
...
1
 
2
3
4
5
 
 
 
6
7
8
9
10
11
 
12
13
14
15
...
53
54
55
 
56
57
0
@@ -1,15 +1,15 @@