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]
41 rescue ActiveRecord::RecordNotFound
42 render :action => "no_such_entry", :status => :not_found
46 @entry = DiaryEntry.find(params[:id])
47 @diary_comment = @entry.diary_comments.build(params[:diary_comment])
48 @diary_comment.user = @user
49 if @diary_comment.save
50 Notifier::deliver_diary_comment_notification(@diary_comment)
51 redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
53 render :action => 'view'
58 if params[:display_name]
59 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
62 @title = @this_user.display_name + "'s diary"
63 @entry_pages, @entries = paginate(:diary_entries,
64 :conditions => ['user_id = ?', @this_user.id],
65 :order => 'created_at DESC',
68 @not_found_user = params[:display_name]
70 render :action => 'no_such_user', :status => :not_found
73 @title = "Users' diaries"
74 @entry_pages, @entries = paginate(:diary_entries, :include => :user,
75 :conditions => ["users.visible = ?", true],
76 :order => 'created_at DESC',
82 if params[:display_name]
83 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
86 @entries = DiaryEntry.find(:all, :conditions => ['user_id = ?', user.id], :order => 'created_at DESC', :limit => 20)
87 @title = "OpenStreetMap diary entries for #{user.display_name}"
88 @description = "Recent OpenStreetmap diary entries from #{user.display_name}"
89 @link = "http://www.openstreetmap.org/user/#{user.display_name}/diary"
91 render :content_type => Mime::RSS
93 render :nothing => true, :status => :not_found
96 @entries = DiaryEntry.find(:all, :include => :user,
97 :conditions => ["users.visible = ?", true],
98 :order => 'created_at DESC', :limit => 20)
99 @title = "OpenStreetMap diary entries"
100 @description = "Recent diary entries from users of OpenStreetMap"
101 @link = "http://www.openstreetmap.org/diary"
103 render :content_type => Mime::RSS
108 user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
111 @entry = DiaryEntry.find(:first, :conditions => ['user_id = ? AND id = ?', user.id, params[:id]])
113 @not_found_user = params[:display_name]
115 render :action => 'no_such_user', :status => :not_found