- @entry = DiaryEntry.new(params[:diary_entry])
- @entry.user = @user
- if @entry.save
- redirect_to :controller => 'user', :action => 'diary', :display_name => @user.display_name
+ @diary_entry = DiaryEntry.new(params[:diary_entry])
+ @diary_entry.user = @user
+
+ if @diary_entry.save
+ redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
+ else
+ render :action => 'edit'
+ end
+ else
+ render :action => 'edit'
+ 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]
+ elsif 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]