1 class DiaryEntryController < ApplicationController
2 layout 'site', :except => :rss
4 before_filter :authorize_web
5 before_filter :require_user, :only => [:new, :edit]
6 before_filter :check_database_availability
9 @title = 'New diary entry'
11 if params[:diary_entry]
12 @diary_entry = DiaryEntry.new(params[:diary_entry])
13 @diary_entry.user = @user
16 redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
18 render :action => 'edit'
21 render :action => 'edit'
26 @title= 'Edit diary entry'
27 @diary_entry = DiaryEntry.find(params[:id])
29 if @user != @diary_entry.user
30 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
31 elsif params[:diary_entry]
32 @diary_entry.title = params[:diary_entry][:title]
33 @diary_entry.body = params[:diary_entry][:body]
34 @diary_entry.latitude = params[:diary_entry][:latitude]
35 @diary_entry.longitude = params[:diary_entry][:longitude]
38 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
44 @entry = DiaryEntry.find(params[:id])
45 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
46 @diary_comment.user = @user
47 if @diary_comment.save
48 Notifier::deliver_diary_comment_notification(@diary_comment)
49 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
51 render :action => 'view'
56 if params[:display_name]
57 @this_user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
60 @title = @this_user.display_name + "'s diary"
61 @entry_pages, @entries = paginate(:diary_entries,
62 :conditions => ['user_id = ?', @this_user.id],
63 :order => 'created_at DESC',
66 @not_found_user = params[:display_name]
68 render :action => 'no_such_user', :status => :not_found
71 @title = "Users' diaries"
72 @entry_pages, @entries = paginate(:diary_entries,
73 :order => 'created_at DESC',
79 if params[:display_name]
80 user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
83 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
84 @title = "OpenStreetMap diary entries for #{user.display_name}"
85 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
86 @link = "http://www.openstreetmap.org/user/#{user.display_name}/diary"
88 render :content_type => Mime::RSS
90 render :nothing => true, :status => :not_found
93 @entries = DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
94 @title = "OpenStreetMap diary entries"
95 @description = "Recent diary entries from users of OpenStreetMap"
96 @link = "http://www.openstreetmap.org/diary"
98 render :content_type => Mime::RSS
103 user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
106 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
108 @not_found_user = params[:display_name]
110 render :action => 'no_such_user', :status => :not_found