+
+ def edit
+ @title = t "diary_entry.edit.title"
+ @diary_entry = DiaryEntry.find(params[:id])
+
+ if @user != @diary_entry.user
+ redirect_to :action => "view", :id => params[:id]
+ elsif params[:diary_entry] && @diary_entry.update_attributes(entry_params)
+ redirect_to :action => "view", :id => params[:id]
+ end
+
+ set_map_location
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
+ end
+
+ def comment
+ @entry = DiaryEntry.find(params[:id])
+ @diary_comment = @entry.comments.build(comment_params)
+ @diary_comment.user = @user
+ if @diary_comment.save
+
+ # Notify current subscribers of the new comment
+ @entry.subscribers.visible.each do |user|
+ if @user != user
+ Notifier.diary_comment_notification(@diary_comment, user).deliver_now
+ end
+ end
+
+ # Add the commenter to the subscribers if necessary
+ @entry.subscriptions.create(:user => @user) unless @entry.subscribers.exists?(@user.id)
+
+ redirect_to :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
+ else
+ render :action => "view"
+ end
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
+ end
+
+ def subscribe
+ diary_entry = DiaryEntry.find(params[:id])
+
+ diary_entry.subscriptions.create(:user => @user) unless diary_entry.subscribers.exists?(@user.id)
+
+ redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
+ end
+
+ def unsubscribe
+ diary_entry = DiaryEntry.find(params[:id])
+
+ diary_entry.subscriptions.where(:user => @user).delete_all if diary_entry.subscribers.exists?(@user.id)
+
+ redirect_to :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
+ end
+