Created
January 18, 2011 21:51
-
-
Save esparkman/785232 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
= form_for ([@ticketable, @ticket]) do |f| | |
= f.error_messages | |
= f.hidden_field :ticketable_id | |
= f.hidden_field :ticketable_type | |
%p | |
= f.label :title, "Brief Title for Issue" | |
= f.text_field :title | |
%p | |
= f.label :call_type | |
%br/ | |
= f.select :call_type, Ticket::Types.collect { |t| [t.first.to_s, t.last] } | |
#ticket_priority_field.field | |
= f.label :priority | |
%br/ | |
= f.select :priority, Ticket.priorities.keys | |
%p | |
= f.label :description | |
%br/ | |
= f.text_area :description | |
%p | |
= f.label :call_back_needed | |
%br/ | |
= f.check_box :call_back_needed | |
%p | |
= f.label :status | |
%br/ | |
= f.select :status, Ticket::Status.collect { |t| [t.first.to_s, t.last] } | |
%p | |
Assigned to: | |
%br/ | |
= f.select("user_id", User.all.collect {|p| [ p.email.to_s, p.id ] }, { :include_blank => true }) | |
%p= f.submit |
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 CompaniesController < ApplicationController | |
# GET /companies | |
# GET /companies.xml | |
def index | |
@companies = Company.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @companies } | |
end | |
end | |
# GET /companies/1 | |
# GET /companies/1.xml | |
def show | |
@company = Company.find(params[:id]) | |
@ticketable = find_ticketable | |
@people = @company.people.paginate :per_page => 25, :page => params[:page], :order => 'last_name' | |
@tickets = @company.tickets.paginate :per_page => 10, :page => params[:page] | |
respond_to do |format| | |
format.html # show.html.erb | |
format.xml { render :xml => @company } | |
end | |
end | |
# GET /companies/new | |
# GET /companies/new.xml | |
def new | |
@company = Company.find(params[:id]) | |
@ticket = Ticket.new(:ticketable => @company) | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @company } | |
end | |
end | |
# GET /companies/1/edit | |
def edit | |
@company = Company.find(params[:id]) | |
end | |
# POST /companies | |
# POST /companies.xml | |
def create | |
@company = Company.new(params[:company]) | |
respond_to do |format| | |
if @company.save | |
format.html { redirect_to(@company, :notice => 'Client was successfully created.') } | |
format.xml { render :xml => @company, :status => :created, :location => @company } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @company.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /companies/1 | |
# PUT /companies/1.xml | |
def update | |
@company = Company.find(params[:id]) | |
respond_to do |format| | |
if @company.update_attributes(params[:company]) | |
format.html { redirect_to(@company, :notice => 'Client was successfully updated.') } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @company.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /companies/1 | |
# DELETE /companies/1.xml | |
def destroy | |
@company = Company.find(params[:id]) | |
@company.destroy | |
respond_to do |format| | |
format.html { redirect_to(companies_url, :notice => 'Client successfully removed.') } | |
format.xml { head :ok } | |
end | |
end | |
private | |
def find_ticketable | |
params.each do |name, value| | |
if name =~ /(.+)_id$/ | |
return $1.classify.constantize.find(value) | |
end | |
end | |
nil | |
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
# == Schema Information | |
# Schema version: 20101206152535 | |
# | |
# Table name: companies | |
# | |
# id :integer(4) not null, primary key | |
# name :string(255) | |
# city :string(255) | |
# state :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# | |
class Company < ActiveRecord::Base | |
has_many :people | |
has_many :tickets, :as => :ticketable | |
def location | |
"#{city}, #{state}" | |
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
NoMethodError in TicketsController#create | |
undefined method `find' for Object:Class | |
Rails.root: /Users/esparkman/Programming/Rails/clientmanager | |
Application Trace | Framework Trace | Full Trace | |
app/controllers/tickets_controller.rb:22:in `create' | |
Request | |
Parameters: | |
{"utf8"=>"✓", | |
"authenticity_token"=>"rpi+by1tvDW5hXQIRuGth/81GWKrJn9se4fnuXSzmW0=", | |
"ticket"=>{"ticketable_id"=>"", | |
"ticketable_type"=>"", | |
"title"=>"fwewefwefwefweff", | |
"call_type"=>"Change", | |
"priority"=>"Low", | |
"description"=>"fwefwefwef", | |
"call_back_needed"=>"0", | |
"status"=>"Open", | |
"user_id"=>"1"}, | |
"commit"=>"Create Ticket"} | |
Show session dump | |
Show env dump | |
Response | |
Headers: | |
None |
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
# == Schema Information | |
# Schema version: 20110110194028 | |
# | |
# Table name: tickets | |
# | |
# id :integer(4) not null, primary key | |
# call_type :string(255) | |
# priority_level :integer(4) | |
# description :text | |
# call_back_needed :boolean(1) | |
# ticketable_id :integer(4) | |
# ticketable_type :string(255) | |
# user_id :integer(4) | |
# status :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# title :string(255) | |
# | |
class Ticket < ActiveRecord::Base | |
belongs_to :ticketable, :polymorphic => true | |
belongs_to :user, :foreign_key => 'user_id', :class_name => 'User' | |
has_many :comments | |
scope :open_tickets, where(:status => 'Open') | |
scope :pending_tickets, where(:status => 'Pending') | |
validates_numericality_of :priority_level, :allow_blank => true | |
# validates_inclusion_of :call_type, :in => Ticket::Types.values, :allow_blank => true | |
# Constants | |
# Types = %w[Incident Problem Question Task] | |
Types = { :- => '', | |
:NewHire => 'New Hire', | |
:Change => 'Change', | |
:Error => 'Error', | |
:Claims => 'Claims', | |
:Question => 'Question', | |
:FollowUp => 'Follow Up', | |
:OfficeNote => 'Office Note', | |
:Task => 'Task' } | |
Status = { :- => '', | |
:Open => 'Open', | |
:Pending => 'Pending', | |
:Closed => 'Closed', | |
:FollowUp => 'Follow Up' | |
} | |
as_enum :priority, { :Low => 0, :Medium => 1, :High => 2, :Urgent => 3 }, :column => :priority_level | |
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
class TicketsController < ApplicationController | |
# before_filter :find_person | |
# before_filter :find_company | |
# before_filter :find_user | |
# before_filter :find_ticket, :only => [:show, :edit, :update, :destroy] | |
def show | |
@ticket = Ticket.find(params[:id]) | |
# @comments = Comment.all | |
# @comment = @ticket.comments.build | |
end | |
def new | |
@ticket = Ticket.new | |
#@ticket = @person.tickets.build | |
end | |
def create | |
@ticket = Ticket.new(params[:ticket]) | |
# @user = current_user | |
if @ticket.save | |
redirect_to [@ticket.ticketable, @ticket], :notice => 'Ticket was created successfully' | |
else | |
flash[:notice] = 'Ticket was not created Successfully.' | |
render = 'new' | |
end | |
end | |
def edit | |
end | |
def update | |
if @ticket.update_attributes(params[:ticket]) | |
flash[:notice] = "Ticket has been updated." | |
redirect_to [@person, @ticket] | |
else | |
flash[:alert] = "Ticket has not been updated." | |
render :action => "edit" | |
end | |
end | |
def destroy | |
@ticket.destroy | |
flash[:notice] = "Ticket has been deleted." | |
redirect_to @person | |
end | |
private | |
#def find_company | |
# @company = Company.find(params[:company_id]) | |
#end | |
#def find_person | |
# @person = Person.find(params[:person_id]) | |
#end | |
#def find_user | |
# @user = User.find(params[:user_id]) | |
#end | |
#def find_ticket | |
# @ticket = @person.tickets.find(params[:id]) | |
#end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment