GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a website in ruby on rails for design showcases. will be used at plasticpilots.com
Clone URL: git://github.com/TomK32/plasticairships.git
a few fixes for finders in the controllers
changed create_guest
* capture and display errors
* send registration mail
moved user form to partial
fixed post#excerpt
rescueing from sites with no assets
TomK32 (author)
Mon Jun 16 00:21:11 -0700 2008
commit  e5f4be827c43c9382f358be42e4989649511f101
tree    acff5ad7de2305b309b7e1cb6fc66339cdb57d82
parent  661cb460d4f3834291ff8f74433f33b67a1d3d91
...
13
14
15
16
 
17
18
19
20
21
22
 
 
 
 
 
23
24
25
...
40
41
42
43
44
 
 
 
 
 
 
45
46
47
...
13
14
15
 
16
17
18
19
20
 
 
21
22
23
24
25
26
27
28
...
43
44
45
 
 
46
47
48
49
50
51
52
53
54
0
@@ -13,13 +13,16 @@ class PostsController < ApplicationController
0
   end
0
   
0
   def admin
0
- @posts = Post.find :all, :conditions => ['published = ?', false], :order => 'id DESC'
0
+ @posts = Post.find_all_by_published(false, :order => 'id DESC')
0
     @posts += Post.published.paginate(:per_page => 20, :page => params[:page])
0
   end
0
   
0
   def show
0
- @post = Post.published.find(:first, params[:id], :include => [:comments, :user])
0
- redirect_to posts_url and return if @post.blank?
0
+ begin
0
+ @post = Post.published.find(params[:id], :include => [:comments, :user])
0
+ rescue ActiveRecord::RecordNotFound => ex
0
+ redirect_to posts_url and return if @post.blank?
0
+ end
0
 
0
     respond_to do |format|
0
       format.html # show.html.erb
0
@@ -40,8 +43,12 @@ class PostsController < ApplicationController
0
   end
0
 
0
   def create
0
- create_guest(params[:user]) unless logged_in?
0
- @post = current_user.posts.new(params[:post])
0
+ @post = Post.new(params[:post])
0
+ unless logged_in?
0
+ @user = create_guest(params[:user])
0
+ render :action => :new and return if @user.new_record?
0
+ end
0
+ @post.user = current_user
0
     @post.published = params[:post][:published] if current_user.moderator?
0
 
0
     respond_to do |format|
...
17
18
19
20
 
21
22
23
24
25
 
 
 
 
 
26
27
28
...
43
44
45
46
47
 
 
 
 
 
 
48
49
50
...
17
18
19
 
20
21
22
23
 
 
24
25
26
27
28
29
30
31
...
46
47
48
 
 
49
50
51
52
53
54
55
56
57
0
@@ -17,12 +17,15 @@ class SitesController < ApplicationController
0
   
0
   def admin
0
     @sites = Site.find_all_by_published(false, :limit => 10)
0
- @sites += Site.published(:per_page => 10, :page => params[:page])
0
+ @sites += Site.published.paginate(:per_page => 10, :page => params[:page])
0
   end
0
 
0
   def show
0
- @site = Site.find_by_id_and_published(params[:id], true, :include => [:comments, :assets])
0
- redirect_to sites_url and return unless @site
0
+ begin
0
+ @site = Site.published(params[:id], :include => [:comments, :user, :assets])
0
+ rescue ActiveRecord::RecordNotFound => ex
0
+ redirect_to sites_url and return unless @site
0
+ end
0
 
0
     respond_to do |format|
0
       format.html # show.html.erb
0
@@ -43,8 +46,12 @@ class SitesController < ApplicationController
0
   end
0
 
0
   def create
0
- create_guest(params[:user]) unless logged_in?
0
- @site = current_user.sites.new(params[:site])
0
+ @site = Site.new(params[:site])
0
+ unless logged_in?
0
+ @user = create_guest(params[:user])
0
+ render :action => :new and return if @user.new_record?
0
+ end
0
+ @site.user = current_user
0
     @site.published = params[:site][:published] if current_user.moderator?
0
     respond_to do |format|
0
       if @site.save
...
24
25
26
 
27
28
29
30
31
...
24
25
26
27
28
29
 
30
31
0
@@ -24,8 +24,8 @@ class Post < ActiveRecord::Base
0
   end
0
 
0
   def excerpt
0
+ return self[:excerpt] unless self[:excerpt].blank?
0
     return self[:body] if self[:body].length < 150
0
     return self[:body][/.{0,150}\w*/] + "..." if self[:excerpt].blank?
0
- self[:excerpt]
0
   end
0
 end
...
19
20
21
22
 
23
24
25
...
36
37
38
 
39
40
41
...
19
20
21
 
22
23
24
25
...
36
37
38
39
40
41
42
0
@@ -19,7 +19,7 @@ class Site < ActiveRecord::Base
0
 # validates_length_of :description, :minimum => 40
0
   
0
   def before_validation
0
- self.permalink = PermalinkFu.escape(self.url_short) if self.permalink.blank?
0
+ self.permalink = PermalinkFu.escape(self.url_short.gsub('www.', '')) if self.permalink.blank?
0
     self.thumbnail_filename = self.screenshot.nil? ? nil : self.screenshot.public_filename(:thumb)
0
   end
0
 
0
@@ -36,6 +36,7 @@ class Site < ActiveRecord::Base
0
   end
0
   
0
   def thumbnail_url(request)
0
+ return false if self.thumbnail_filename.blank?
0
     request.protocol + request.host_with_port + self.thumbnail_filename
0
   end
0
   
...
1
 
2
3
4
...
10
11
12
13
14
15
16
17
18
19
20
21
 
22
23
24
...
 
1
2
3
4
...
10
11
12
 
 
 
 
 
 
 
 
 
13
14
15
16
0
@@ -1,4 +1,4 @@
0
-<h1>New post</h1>
0
+<% @page_title = 'Add a new post' %>
0
 
0
 <%= error_messages_for :post %>
0
 
0
@@ -10,15 +10,7 @@
0
   <legend>Your data</data>
0
   <p>You are not logged in but if you already have an account, you may <%= link_to 'login', login_url %> first. If you don't have an account yet, you can type in your email address and <em>we will create an account for you</em>.</p>
0
   <% fields_for :user do |fu| %>
0
- <p><%= fu.label :name, 'Name' %><br />
0
- <%= fu.text_field :name %>
0
- </p>
0
- <p><%= fu.label :email, 'E-Mail' %><br />
0
- <%= fu.text_field :email %>
0
- </p>
0
- <p><%= fu.label :website, 'Website' %><br />
0
- <%= fu.text_field :website %>
0
- </p>
0
+ <%= render :partial => '/users/form', :locals => {:f => fu} %>
0
   <% end %>
0
   </fieldset>
0
   <% end %>
...
2
3
4
5
6
7
 
 
 
 
8
9
10
...
2
3
4
 
 
 
5
6
7
8
9
10
11
0
@@ -2,9 +2,10 @@
0
 <div class="post">
0
 <div class="meta">
0
   posted by <%= link_to h(@post.user.name), user_url(@post.user) %> on <%= @post.published_at.to_formatted_s(:long) %><br />
0
- tags: <span class="tags"><%= link_to_tags(@post.cached_tag_list, :posts) %></span>
0
-</div>
0
-<%= textilize(@post.body) %>
0
+ tags: <span class="tags"><%= @post.cached_tag_list %></span>
0
+ </div>
0
+ <%= textilize(@post.excerpt) %>
0
+ <%= textilize(@post.body) %>
0
 
0
 <div id="comments">
0
 <h3>Comments</h3>
...
1
2
 
3
4
...
1
 
2
3
4
0
@@ -1,4 +1,4 @@
0
 <p>
0
-<%= image_tag(site.thumbnail_url(request), :style => "float:left;") %>
0
+<%= image_tag(site.thumbnail_url(request), :style => "float:left;") if site.thumbnail_url %>
0
 <%= textilize site.description %>
0
 </p>
...
6
7
8
9
 
 
10
11
12
...
6
7
8
 
9
10
11
12
13
0
@@ -6,7 +6,8 @@
0
 <% if latest_sites(14).blank? %>
0
 <p>No sites so far</p>
0
 <% else %>
0
- <% latest_sites(14).each do |site| %>
0
+ <% latest_sites(14).each do |site|
0
+ next if site.screenshot.nil? %>
0
   <%= link_to image_tag(site.screenshot.public_filename(:tiny), :alt => site.title), site_url(site), :title => [site.title, site.description].join(" - ") %>
0
   <% end %>
0
 <% end %>
...
5
6
7
 
 
8
9
...
5
6
7
8
9
10
11
0
@@ -5,5 +5,7 @@
0
   <h3><%= link_to h(site.title), site %></h3>
0
 
0
   <%= textilize(site.description) %>
0
+
0
+ <%= link_to site.url_short, site.url %> //
0
   <%= link_to pluralize(site.comments_count, 'comment'), site_path(site) + '#comments' %>
0
 </div>
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 <% @page_title = 'sites administration' %>
0
 
0
 <% @sites.each do |site| %>
0
- <div id="site-<%= site.id%>" class="<%= 'featured ' if site.featured? %><%= 'published' if site.published? %>"><%= link_to h(site.title), site %> by <%= link_to site.user.name, user_url(site.user_id) %> on <%= site.created_at.to_s(:long) %> is <%= 'not' unless site.published? %> published and has <%= pluralize(site.comments_count, 'comment') %><br />
0
+ <div id="site-<%= site.id%>" class="<%= 'featured ' if site.featured? %><%= 'published' if site.published? %>"><%= link_to h(site.title), site %> <%= link_to h(site.url_short), site.url %> by <%= link_to site.user.name, user_url(site.user_id) %> on <%= site.created_at.to_s(:long) %> is <%= 'not' unless site.published? %> published and has <%= pluralize(site.comments_count, 'comment') %><br />
0
   <% unless site.published %>
0
   <%= link_to 'publish', publish_site_url(site), :method => :put %> |
0
   <% end %>
...
1
2
3
4
 
5
6
 
7
8
...
1
2
3
 
4
5
 
6
7
8
0
@@ -1,7 +1,7 @@
0
 <% @page_title = 'featured sites' %>
0
 
0
 <div id="sites">
0
- <%= will_paginate @posts %>
0
+
0
   <%= render :partial => "site", :collection => @sites %>
0
- <%= will_paginate @posts %>
0
+ <%= will_paginate @sites %>
0
 </div>
0
\ No newline at end of file
...
10
11
12
13
14
15
16
17
18
19
20
21
 
22
23
24
...
10
11
12
 
 
 
 
 
 
 
 
 
13
14
15
16
0
@@ -10,15 +10,7 @@
0
   <legend>Your data</data>
0
   <p>You are not logged in but if you already have an account, you may <%= link_to 'login', login_url %> first. If you don't have an account yet, you can type in your email address and <em>we will create an account for you</em>.</p>
0
   <% fields_for :user do |fu| %>
0
- <p><%= fu.label :name, 'Name' %><br />
0
- <%= fu.text_field :name %>
0
- </p>
0
- <p><%= fu.label :email, 'E-Mail' %><br />
0
- <%= fu.text_field :email %>
0
- </p>
0
- <p><%= fu.label :website, 'Website' %><br />
0
- <%= fu.text_field :website %>
0
- </p>
0
+ <%= render :partial => '/users/form', :locals => {:f => fu } %>
0
   <% end %>
0
   </fieldset>
0
   <% end %>
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 <% @page_title = h(@site.title) %>
0
+<%= link_to @site.url_short, @site.url, :class => 'site_url' %>
0
 <div class="site">
0
 <div class="body"><%= textilize(@site.description) %></div>
0
 
...
28
29
30
31
 
32
33
34
...
28
29
30
 
31
32
33
34
0
@@ -28,7 +28,7 @@ end
0
 
0
 module Goldberg
0
   class User
0
- validates_uniqueness_of :name, :unless => Proc.new {|record| record.name == 'guest' }
0
+ validates_presence_of :email
0
     
0
     def is_guest?
0
       name =~ /^guest/

Comments

    No one has commented yet.