+
+ def edit
+ @title = t "diary_entry.edit.title"
+ @diary_entry = DiaryEntry.find(params[:id])
+
+ if current_user != @diary_entry.user
+ redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
+ elsif params[:diary_entry] && @diary_entry.update(entry_params)
+ redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
+ 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 = current_user
+ if @diary_comment.save
+
+ # Notify current subscribers of the new comment
+ @entry.subscribers.visible.each do |user|
+ Notifier.diary_comment_notification(@diary_comment, user).deliver_now if current_user != user
+ end
+
+ # Add the commenter to the subscribers if necessary
+ @entry.subscriptions.create(:user => current_user) unless @entry.subscribers.exists?(current_user.id)
+
+ redirect_to diary_entry_path(@entry.user, @entry)
+ else
+ render :action => "show"
+ 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 => current_user) unless diary_entry.subscribers.exists?(current_user.id)
+
+ redirect_to diary_entry_path(diary_entry.user, diary_entry)
+ 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 => current_user).delete_all if diary_entry.subscribers.exists?(current_user.id)
+
+ redirect_to diary_entry_path(diary_entry.user, diary_entry)
+ rescue ActiveRecord::RecordNotFound
+ render :action => "no_such_entry", :status => :not_found
+ end
+
+ def index