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_readable
7 before_filter :check_database_writable, :only => [:new, :edit]
10 @title = 'New diary entry'
12 if params[:diary_entry]
13 @diary_entry = DiaryEntry.new(params[:diary_entry])
14 @diary_entry.user = @user
17 redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
19 render :action => 'edit'
22 render :action => 'edit'
27 @title= 'Edit diary entry'
28 @diary_entry = DiaryEntry.find(params[:id])
30 if @user != @diary_entry.user
31 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
32 elsif params[:diary_entry]
33 @diary_entry.title = params[:diary_entry][:title]
34 @diary_entry.body = params[:diary_entry][:body]
35 @diary_entry.latitude = params[:diary_entry][:latitude]
36 @diary_entry.longitude = params[:diary_entry][:longitude]
39 redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
42 rescue ActiveRecord::RecordNotFound
43 render :action => "no_such_entry", :status => :not_found
47 @entry = DiaryEntry.find(params[:id])
48 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
49 @diary_comment.user = @user
50 if @diary_comment.save
51 Notifier::deliver_diary_comment_notification(@diary_comment)
52 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
54 render :action => 'view'
59 if params[:display_name]
60 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
63 @title = @this_user.display_name + "'s diary"
64 @entry_pages, @entries = paginate(:diary_entries,
65 :conditions => ['user_id = ?', @this_user.id],
66 :order => 'created_at DESC',
69 @not_found_user = params[:display_name]
71 render :action => 'no_such_user', :status => :not_found
74 @title = "Users' diaries"
75 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
76 :conditions => ["users.visible = ?", true],
77 :order => 'created_at DESC',
83 if params[:display_name]
84 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
87 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
88 @title = "OpenStreetMap diary entries for #{user.display_name}"
89 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
90 @link = "http://#{SERVER_URL}/user/#{user.display_name}/diary"
92 render :content_type => Mime::RSS
94 render :nothing => true, :status => :not_found
97 @entries = DiaryEntry.find(:all, :include => :user,
98 :conditions => ["users.visible = ?", true],
99 :order => 'created_at DESC', :limit => 20)
100 @title = "OpenStreetMap diary entries"
101 @description = "Recent diary entries from users of OpenStreetMap"
102 @link = "http://#{SERVER_URL}/diary"
104 render :content_type => Mime::RSS
109 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
112 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
113 @title = "Users' diaries | #{params[:display_name]}"
115 @not_found_user = params[:display_name]
117 render :action => 'no_such_user', :status => :not_found