end
end
end
+
+ def comment
+ @entry = DiaryEntry.find(params[:id])
+ @diary_comment = @entry.diary_comments.build(params[:diary_comment])
+ @diary_comment.user = @user
+ if @diary_comment.save
+ redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
+ else
+ render :action => 'view'
+ end
+ end
def list
if params[:display_name]
@this_user = User.find_by_display_name(params[:display_name])
@title = @this_user.display_name + "'s diary"
- if params[:id]
- @entries=DiaryEntry.find(:all, :conditions => ['user_id = ? AND id = ?', @this_user.id, params[:id]])
- else
- @entries=DiaryEntry.find(:all, :conditions => ['user_id = ?', @this_user.id], :order => 'created_at DESC')
- end
+ @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', @this_user.id], :order => 'created_at DESC')
else
- @title = 'recent diary entries'
- @entries=DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
+ @title = "Users' diaries"
+ @entries = DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
end
end
render :content_type => Mime::RSS
end
+
+ def view
+ user = User.find_by_display_name(params[:display_name])
+ @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
+ end
end
--- /dev/null
+class DiaryComment < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :diary_entry
+
+ validates_presence_of :body
+ validates_associated :diary_entry
+end
class DiaryEntry < ActiveRecord::Base
belongs_to :user
+ has_many :diary_comments, :order => "id"
validates_presence_of :title, :body
validates_numericality_of :latitude, :allow_nil => true
--- /dev/null
+<h4>Comment from <%= link_to diary_comment.user.display_name, :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name %> at <%= diary_comment.created_at %></h4>
+<%= htmlize(diary_comment.body) %>
+<hr />
-<b><%= h(diary_entry.title) %></b><br />
+<b><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></b><br />
<%= htmlize(diary_entry.body) %>
<% if diary_entry.latitude and diary_entry.longitude %>
Coordinates: <div class="geo" style="display: inline"><span class="latitude"><%= diary_entry.latitude %></span>; <span class="longitude"><%= diary_entry.longitude %></span></div> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => diary_entry.latitude, :lon => diary_entry.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => diary_entry.latitude, :lon => diary_entry.longitude, :zoom => 14 %>)<br/>
<% end %>
Posted by <b><%= link_to diary_entry.user.display_name, :controller => 'user', :action => 'view', :display_name => diary_entry.user.display_name %></b> at <%= diary_entry.created_at %><br />
+<% if params[:action] == 'list' %>
+<%= link_to 'Comment on this entry', :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comment' %>
+|
+<%= link_to 'Reply to this entry', :controller => 'message', :action => 'new', :user_id => diary_entry.user.id, :title => "Re: #{diary_entry.title}" %>
+<% end %>
<br />
<hr />
+<h2><%= @title %></h2>
<% if @this_user %>
- <h2><%= @this_user.display_name %>'s diary</h2>
<% if @user == @this_user %>
<%= link_to 'New diary post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
<% end %>
<% else %>
- <h2>Users' diaries</h2>
<% if @user %>
<%= link_to 'New diary post', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %>
<% end %>
<h3>Recent diary entries:</h3>
-<%= render :partial => 'diary_entry/diary_entry', :collection => @entries %>
+<%= render :partial => 'diary_entry', :collection => @entries %>
<%= link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), :action => 'rss') %>
<%= auto_discovery_link_tag(:atom, :action => 'rss') %>
--- /dev/null
+<h2><%= @entry.user.display_name %>'s diary</h2>
+
+<%= render :partial => 'diary_entry', :object => @entry %>
+
+<%= render :partial => 'diary_comment', :collection => @entry.diary_comments %>
+
+<% if @user %>
+
+<h4 id="comment">Leave a comment</h4>
+<%= error_messages_for 'diary_comment' %>
+<% form_for :diary_comment, @diary_comment, :url => { :action => 'comment' } do |f| %>
+<%= f.text_area :body, :cols => 80, :rows => 5 %>
+<br />
+<br />
+<%= submit_tag 'Save' %>
+<% end %>
+
+<% else %>
+
+<h4 id="comment"><%= link_to "Login", :controller => 'user', :action => 'login', :referer => request.request_uri %> to leave a comment</h4>
+
+<% end %>
map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
map.connect '/user/:display_name/remove_friend', :controller => 'user', :action => 'remove_friend'
map.connect '/user/:display_name/diary', :controller => 'diary_entry', :action => 'list'
- map.connect '/user/:display_name/diary/:id', :controller => 'diary_entry', :action => 'list', :id => /\d+/
+ map.connect '/user/:display_name/diary/:id', :controller => 'diary_entry', :action => 'view', :id => /\d+/
+ map.connect '/user/:display_name/diary/:id/newcomment', :controller => 'diary_entry', :action => 'comment', :id => /\d+/
map.connect '/user/:display_name/diary/rss', :controller => 'diary_entry', :action => 'rss'
map.connect '/user/:display_name/diary/newpost', :controller => 'diary_entry', :action => 'new'
map.connect '/user/:display_name/account', :controller => 'user', :action => 'account'
--- /dev/null
+class DiaryComments < ActiveRecord::Migration
+ def self.up
+ create_table "diary_comments", myisam_table do |t|
+ t.column "id", :bigint, :limit => 20, :null => false
+ t.column "diary_entry_id", :bigint, :limit => 20, :null => false
+ t.column "user_id", :bigint, :limit => 20, :null => false
+ t.column "body", :text, :null => false
+ t.column "created_at", :datetime, :null => false
+ t.column "updated_at", :datetime, :null => false
+ end
+
+ add_primary_key "diary_comments", ["id"]
+ add_index "diary_comments", ["diary_entry_id", "id"], :name => "diary_comments_entry_id_idx", :unique => true
+
+ change_column "diary_comments", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT"
+ end
+
+ def self.down
+ drop_table "diary_comments"
+ end
+end