]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/diary_entry_controller.rb
edit diary entries
[rails.git] / app / controllers / diary_entry_controller.rb
index afd06259d212a9994576c307654b2ef21c4d52d4..0ad71da17ba99efa0db7eea33dfe8fad72488d69 100644 (file)
@@ -2,7 +2,7 @@ class DiaryEntryController < ApplicationController
   layout 'site', :except => :rss
 
   before_filter :authorize_web
-  before_filter :require_user, :only => [:new]
+  before_filter :require_user, :only => [:new, :edit]
   before_filter :check_database_availability
 
   def new
@@ -16,6 +16,23 @@ class DiaryEntryController < ApplicationController
     end
   end
 
+  def edit
+    @title= 'edit diary entry'
+    @diary_entry = DiaryEntry.find(params[:id])
+    if @user != @diary_entry.user
+         redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
+    end
+    if params[:diary_entry]
+      @diary_entry.title = params[:diary_entry][:title]
+      @diary_entry.body = params[:diary_entry][:body]
+      @diary_entry.latitude = params[:diary_entry][:latitude]
+      @diary_entry.longitude = params[:diary_entry][:longitude]
+      if @diary_entry.save
+        redirect_to :controller => 'diary_entry', :action => 'view', :id => params[:id]
+         end
+    end
+  end
+
   def comment
     @entry = DiaryEntry.find(params[:id])
     @diary_comment = @entry.diary_comments.build(params[:diary_comment])
@@ -63,7 +80,7 @@ class DiaryEntryController < ApplicationController
         render :content_type => Mime::RSS
       else
         render :nothing => true, :status => :not_found
-      endif
+      end
     else
       @entries = DiaryEntry.find(:all, :order => 'created_at DESC', :limit => 20)
       @title = "OpenStreetMap diary entries"