From 1e98eb99504836794fbfce1cacc6bce93a8e4983 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 7 Jul 2008 23:26:41 +0000 Subject: [PATCH] Allow users to remove their image. Closes #1010. --- app/controllers/user_controller.rb | 10 ++++++++-- app/views/user/view.rhtml | 7 +++++-- config/routes.rb | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 5d26708fe..fd58145c4 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -2,8 +2,8 @@ class UserController < ApplicationController layout 'site' before_filter :authorize, :only => [:api_details, :api_gpx_files] - before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image] - before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image] + before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image, :delete_image] + before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image] before_filter :check_database_availability, :except => [:api_details, :api_gpx_files] before_filter :check_read_availability, :only => [:api_details, :api_gpx_files] @@ -167,6 +167,12 @@ class UserController < ApplicationController redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name end + def delete_image + @user.image = nil + @user.save! + redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name + end + def api_details render :text => @user.to_xml.to_s, :content_type => "text/xml" end diff --git a/app/views/user/view.rhtml b/app/views/user/view.rhtml index c5fc6388d..3ee8ecb86 100644 --- a/app/views/user/view.rhtml +++ b/app/views/user/view.rhtml @@ -20,7 +20,10 @@

User image

<% if @this_user.image %> - <%= image_tag url_for_file_column(@this_user, "image") %> + <%= image_tag url_for_file_column(@this_user, "image") %> + <% if @user and @this_user.id == @user.id %> + <%= button_to 'Delete Image', :action => 'delete_image' %> + <% end %> <% end %>
@@ -28,7 +31,7 @@ Upload an image
<%= form_tag({:action=>'upload_image'}, :multipart => true)%> <%= file_column_field 'user', 'image' %> - + <%= submit_tag 'Add Image' %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 854e7f003..2ff56af39 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,6 +81,7 @@ ActionController::Routing::Routes.draw do |map| map.connect '/user/go_public', :controller => 'user', :action => 'go_public' map.connect '/user/reset-password', :controller => 'user', :action => 'reset_password' map.connect '/user/upload-image', :controller => 'user', :action => 'upload_image' + map.connect '/user/delete-image', :controller => 'user', :action => 'delete_image' map.connect '/user/forgot-password', :controller => 'user', :action => 'lost_password' map.connect '/index.html', :controller => 'site', :action => 'index' -- 2.43.2