Created
May 8, 2012 04:12
-
-
Save MikeSilvis/2632517 to your computer and use it in GitHub Desktop.
Ticket Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What an amazing gist.