+
+ def edit
+ @title = t "diary_entry.edit.title"
+ @diary_entry = DiaryEntry.find(params[:id])
+
+ if current_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 = current_user
+ if @diary_comment.save
+
+ # Notify current subscribers of the new comment
+ @entry.subscribers.visible.each do |user|
+ if current_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 => current_user) unless @entry.subscribers.exists?(current_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 => current_user) unless diary_entry.subscribers.exists?(current_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 => current_user).delete_all if diary_entry.subscribers.exists?(current_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
+