Skip to content

Commit

Permalink
Add cancellation links for instructions and a destroy-account option
Browse files Browse the repository at this point in the history
  • Loading branch information
marktabler committed Jul 5, 2012
1 parent 6060ffc commit f672c99
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base
#DEV_MODE = Rails.env == "development" ? true : false
DEV_MODE = false
DEV_MODE = true
protect_from_forgery

def login_required
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/instructions_controller.rb
Expand Up @@ -13,6 +13,12 @@ def create
def new

end

def destroy
@instruction = Instruction.find(params[:id])
@instruction.destroy
return redirect_to instructions_path
end

def update
@instruction = current_user.instructions.find(params[:id])
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/users_controller.rb
@@ -1,6 +1,6 @@

class UsersController < ApplicationController

before_filter :login_required, only: :destroy
def generate_reports
if params[:pw] == INTERNAL_PASSWORD
User.all.each do |user|
Expand All @@ -10,4 +10,13 @@ def generate_reports
return render nothing: true, status: 403
end
end

def destroy
current_user.reports.destroy_all
current_user.alerts.destroy_all
current_user.instructions.destroy_all
current_user.destroy
session["uid"] = nil
return redirect_to root_path
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -33,4 +33,10 @@ def report_links
end
end

def account_controls
if current_user
content_tag(:li, link_to("Cancel Account", user_path(current_user), method: :delete, confirm: "This will destroy all instructions and reports associated with your account. Continue?"))
end
end

end
4 changes: 4 additions & 0 deletions app/views/instructions/_honey_badger.html.erb
@@ -1,3 +1,4 @@
<% show_delete = defined?(delete_option) %>
<% @p = instruction.params || {} %>
<%= form_for instruction do |f| %>
Expand All @@ -12,5 +13,8 @@
<% end %>
<br />
<%= f.submit %>
<% if show_delete%>
<%= button_to "Cancel Instruction", instruction_path(instruction), method: :delete, confirm: "Are you sure you wish to cancel this instruction?" %>
<% end %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/instructions/_stock_ferret.html.erb
@@ -1,3 +1,4 @@
<% show_delete = defined?(delete_option) %>
<% @p = instruction.params || {} %>
<%= form_for instruction do |f| %>
Expand All @@ -22,5 +23,8 @@
<% end %>
<br />
<%= f.submit %>
<% if show_delete%>
<%= button_to "Cancel Instruction", instruction_path(instruction), method: :delete, confirm: "Are you sure you wish to cancel this instruction?" %>
<% end %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/instructions/_weather_ferret.html.erb
@@ -1,3 +1,4 @@
<% show_delete = defined?(delete_option) %>
<% @p = instruction.params || {} %>
<%= form_for instruction do |f| %>
<%= field_set_tag 'Weather Ferret' do %>
Expand All @@ -17,5 +18,8 @@
<% end %>
<br />
<%= f.submit %>
<% if show_delete%>
<%= button_to "Cancel Instruction", instruction_path(instruction), method: :delete, confirm: "Are you sure you wish to cancel this instruction?" %>
<% end %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/instructions/index.html.erb
Expand Up @@ -3,7 +3,7 @@
<div class="row">
<% @instructions.each do |instruction| %>
<div class="span2 ferret">
<%= render partial: instruction.ferret_type.underscore, locals: {instruction: instruction} %>
<%= render partial: instruction.ferret_type.underscore, locals: {instruction: instruction, delete_option: true} %>
</div>
<% end %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/_navbar.html.erb
Expand Up @@ -6,7 +6,9 @@
<%= instruction_links %>
<%= report_links %>
<%= session_controls %>
<%= account_controls %>
<%= salutation %>

</div>
</div>
</div>
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -9,5 +9,5 @@
resources :reports
resource :session
resources :alerts, only: :create

resources :users, only: :destroy
end

0 comments on commit f672c99

Please sign in to comment.