Created
February 4, 2010 19:32
-
-
Save jzellman/295012 to your computer and use it in GitHub Desktop.
This file contains 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 IncomingTicketHandler | |
require 'rubygems' | |
require 'tmail' | |
def self.receive(email) | |
ticket = Ticket.new | |
ticket.title = email.subject | |
ticket.body = email.body | |
ticket.assignedTo = email.to | |
ticket.creator = email.from | |
ticket.priority = 1 | |
ticket.save | |
ticket | |
end | |
end | |
# verses... | |
class IncomingTicketHandler | |
def self.receive(email) | |
# create! causes an exception to be thrown if Ticket validation fails. This may | |
# not be what you want. Example usage: | |
# begin | |
# ticket = IncomingTicketHandler.receive(some_message) | |
# rescue ActiveRecord::RecordInvalid => error | |
# # handle invalid ticket ... | |
# | |
# If you dont want an exception raised on an invalid ticket consider Ticket.create instead. | |
# Remember that Ticket.create will not save if there are validation errors. | |
# So if you use Ticket.create you will need to handle validation in the caller. For | |
# example: | |
# ticket = IncomingTicketHandler.receive(some_message) | |
# unless ticket.save | |
# # handle invalid ticket... | |
# end | |
Ticket.create!(:title => title, :body => email.body, :assignedTo => email.to, | |
:creator => email.from, :priority => 1) | |
end | |
end | |
This file contains 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
# GET /tickets/new | |
# GET /tickets/new.xml | |
def new | |
@ticket = Ticket.new | |
@creators = User.find(:all) | |
@clients = Array.new | |
@assigned_tos = User.find(:all) | |
@assigned_tos.each do |e| | |
if e.role.exists?(:name => "Client") | |
@clients << e | |
end | |
end | |
@assigned_tos = @assigned_tos - @clients | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @ticket } | |
end | |
end | |
# verses... | |
# GET /tickets/new | |
# GET /tickets/new.xml | |
def new | |
@ticket = Ticket.new | |
all_users = User.(:all) | |
@creators = all_users.dup | |
@clients = all_users.select(&:client?) | |
# this also works: | |
# @clients = all_users.select{|user| user.client? } | |
@assigned_tos = all_users - @clients | |
# this would work as well, use whatever you find more clear | |
# @assigned_tos = all_users.reject(&:client?) | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @ticket } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment