From dea7680b7260224beb2d2b8b901310f27d7337b0 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 22 Jan 2013 11:17:10 -0800 Subject: Makes tickets_controller a bit less complex. --- help/app/controllers/tickets_controller.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'help/app/controllers/tickets_controller.rb') diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 372ff6e..3ccebb3 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -15,13 +15,11 @@ class TicketsController < ApplicationController def create @ticket = Ticket.new(params[:ticket]) - if logged_in? - @ticket.created_by = current_user.id - @ticket.email = current_user.email if current_user.email - @ticket.comments.last.posted_by = current_user.id - else - @ticket.comments.last.posted_by = nil #hacky, but protecting this attribute doesn't work right, so this should make sure it isn't set. - end + + @ticket.comments.last.posted_by = (logged_in? ? current_user.id : nil) #protecting posted_by isn't working, so this should protect it. + @ticket.created_by = current_user.id if logged_in? + @ticket.email = current_user.email if logged_in? and current_user.email + flash[:notice] = 'Ticket was successfully created.' if @ticket.save if !logged_in? # cannot set this until ticket has been saved, as @ticket.id will not be set -- cgit v1.2.3