Skip to content

Instantly share code, notes, and snippets.

@MikeSilvis
Created May 8, 2012 04:12
Show Gist options
  • Save MikeSilvis/2632517 to your computer and use it in GitHub Desktop.
Save MikeSilvis/2632517 to your computer and use it in GitHub Desktop.
Ticket Update
class TicketsController < ApplicationController
def index
@create_ticket = Ticket.new
@new_tickets = Ticket.where("state='new'");
@current_tickets = Ticket.where("state='current'");
@completed_tickets = Ticket.where("state='completed'");
end
def show
end
def new
@ticket = Ticket.new
end
def create
@ticket = Ticket.new(params[:ticket])
if @ticket.save
redirect_to tickets_path, :notice => 'Your ticket has been saved'
else
render 'new'
end
end
def edit
@ticket = Ticket.find(params[:id])
end
def update
@ticket = Ticket.find(params[:id]);
if @ticket.update_attributes(params[:ticket])
redirect_to tickets_path, :notice => 'The ticket has been updated'
else
redirect_to tickets_path, :notice => 'Sorry, the update was unsuccesful'
end
end
def destroy
@ticket = Ticket.find(params[:id])
if @ticket.destroy
redirect_to tickets_path, :notice => 'Your ticket has been removed'
end
end
def start
ticket = Ticket.find(params[:id])
if !ticket.current?
ticket.start
ticket.save
redirect_to tickets_path, :notice => 'Your ticket has been started!'
return
end
redirect_to tickets_path, :notice => 'This ticket was already in progress!'
end
def complete
ticket = Ticket.find(params[:id])
if ticket.current? && !ticket.completed?
ticket.complete
ticket.save
redirect_to tickets_path, :notice => "Ticket \##{ticket.id} has been completed!"
return
end
redirect_to tickets_path, :notice => 'This ticket was already in finished'
end
end
@j3j3
Copy link

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment