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]
45 @entry = DiaryEntry.find(params[:id])
46 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
47 @diary_comment.user = @user
48 if @diary_comment.save
49 Notifier::deliver_diary_comment_notification(@diary_comment)
50 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
52 render :action => 'view'
57 if params[:display_name]
58 @this_user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
61 @title = @this_user.display_name + "'s diary"
62 @entry_pages, @entries = paginate(:diary_entries,
63 :conditions => ['user_id = ?', @this_user.id],
64 :order => 'created_at DESC',
67 @not_found_user = params[:display_name]
69 render :action => 'no_such_user', :status => :not_found
72 @title = "Users' diaries"
73 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
74 :conditions => "users.visible = 1",
75 :order => 'created_at DESC',
81 if params[:display_name]
82 user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
85 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
86 @title = "OpenStreetMap diary entries for #{user.display_name}"
87 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
88 @link = "http://www.openstreetmap.org/user/#{user.display_name}/diary"
90 render :content_type => Mime::RSS
92 render :nothing => true, :status => :not_found
95 @entries = DiaryEntry.find(:all, :include => :user,
96 :conditions => "users.visible = 1",
97 :order => 'created_at DESC', :limit => 20)
98 @title = "OpenStreetMap diary entries"
99 @description = "Recent diary entries from users of OpenStreetMap"
100 @link = "http://www.openstreetmap.org/diary"
102 render :content_type => Mime::RSS
107 user = User.find_by_display_name(params[:display_name], :conditions => "visible = 1")
110 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
112 @not_found_user = params[:display_name]
114 render :action => 'no_such_user', :status => :not_found