Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created January 19, 2011 15:30
Show Gist options
  • Save esparkman/786311 to your computer and use it in GitHub Desktop.
Save esparkman/786311 to your computer and use it in GitHub Desktop.
= form_for ([@ticketable, @ticket]) do |f|
= debug @ticket
= debug @ticketable
= f.error_messages
%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
--- !ruby/object:Ticket
attributes:
call_type:
priority_level:
description:
call_back_needed:
ticketable_id: 3
ticketable_type: Company
user_id:
status:
created_at:
updated_at:
title:
attributes_cache: {}
changed_attributes:
ticketable_id:
ticketable_type:
destroyed: false
marked_for_destruction: false
persisted: false
previously_changed: {}
readonly: false
---
=============== Phusion Passenger Standalone web server started ===============
PID file: /Users/esparkman/Programming/Rails/clientmanager/tmp/pids/passenger.3000.pid
Log file: /Users/esparkman/Programming/Rails/clientmanager/log/passenger.3000.log
Environment: development
Accessible via: http://0.0.0.0:3000/
You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
Started GET "/companies/3/tickets/new" for 127.0.0.1 at 2011-01-19 10:28:07 -0500
Processing by TicketsController#new as HTML
Parameters: {"company_id"=>"3"}
SQL (0.6ms) SHOW TABLES
SQL (0.5ms) SHOW TABLES
User Load (1.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
Company Load (0.3ms) SELECT `companies`.* FROM `companies` WHERE (`companies`.`id` = 3) LIMIT 1
User Load (0.4ms) SELECT `users`.* FROM `users`
Rendered tickets/_form.html.haml (24.3ms)
Rendered shared/_pagetitle.html.haml (3.7ms)
Rendered tickets/new.html.haml within layouts/application (49.8ms)
Completed 200 OK in 251ms (Views: 55.1ms | ActiveRecord: 2.7ms | Sphinx: 0.0ms)
Started POST "/tickets" for 127.0.0.1 at 2011-01-19 10:28:25 -0500
Processing by TicketsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"FCQliIsu929n1sMtDBS8LsRUt43RFRctZCVpZ5DaTFk=", "ticket"=>{"title"=>"Test 1", "call_type"=>"New Hire", "priority"=>"Medium", "description"=>"effewfwef", "call_back_needed"=>"0", "status"=>"Open", "user_id"=>"2"}, "commit"=>"Create Ticket"}
SQL (0.4ms) SHOW TABLES
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
Completed in 98ms
ActiveRecord::RecordNotFound (ActiveRecord::RecordNotFound):
app/controllers/tickets_controller.rb:48:in `ticketable'
app/controllers/tickets_controller.rb:15:in `create'
Rendered /Users/esparkman/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
Rendered /Users/esparkman/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.8ms)
Rendered /Users/esparkman/.rvm/gems/ruby-1.9.2-p136@rails3/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.8ms)
<h2>New Ticket</h2>
<form accept-charset="UTF-8" action="/tickets" class="new_ticket" id="new_ticket" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="FCQliIsu929n1sMtDBS8LsRUt43RFRctZCVpZ5DaTFk=" /></div>
<pre class='debug_dump'>--- !ruby/object:Ticket
attributes:
&nbsp; call_type:
&nbsp; priority_level:
&nbsp; description:
&nbsp; call_back_needed:
&nbsp; ticketable_id: 3
&nbsp; ticketable_type: Company
&nbsp; user_id:
&nbsp; status:
&nbsp; created_at:
&nbsp; updated_at:
&nbsp; title:
attributes_cache: {}
changed_attributes:
&nbsp; ticketable_id:
&nbsp; ticketable_type:
destroyed: false
marked_for_destruction: false
persisted: false
previously_changed: {}
readonly: false
</pre>
<pre class='debug_dump'>---
</pre>
<p>
<label for="ticket_title">Brief Title for Issue</label>
<input id="ticket_title" name="ticket[title]" size="30" type="text" />
</p>
<p>
<label for="ticket_call_type">Call type</label>
<br>
<select id="ticket_call_type" name="ticket[call_type]"><option value="">-</option>
<option value="New Hire">NewHire</option>
<option value="Change">Change</option>
<option value="Error">Error</option>
<option value="Claims">Claims</option>
<option value="Question">Question</option>
<option value="Follow Up">FollowUp</option>
<option value="Office Note">OfficeNote</option>
<option value="Task">Task</option></select>
</p>
<div class='field' id='ticket_priority_field'>
<label for="ticket_priority">Priority</label>
<br>
<select id="ticket_priority" name="ticket[priority]"><option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Urgent">Urgent</option></select>
</div>
<p>
<label for="ticket_description">Description</label>
<br>
<textarea cols="40" id="ticket_description" name="ticket[description]" rows="20"></textarea>
</p>
<p>
<label for="ticket_call_back_needed">Call back needed</label>
<br>
<input name="ticket[call_back_needed]" type="hidden" value="0" /><input id="ticket_call_back_needed" name="ticket[call_back_needed]" type="checkbox" value="1" />
</p>
<p>
<label for="ticket_status">Status</label>
<br>
<select id="ticket_status" name="ticket[status]"><option value="">-</option>
<option value="Open">Open</option>
<option value="Pending">Pending</option>
<option value="Closed">Closed</option>
<option value="Follow Up">FollowUp</option></select>
</p>
<p>
Assigned to:
<br>
<select id="ticket_user_id" name="ticket[user_id]"><option value=""></option>
<option value="1">evan.sparkman@starrobbins.com</option>
<option value="2">staci.sparkman@starrobbins.com</option>
<option value="3">esparkman@esdezines.com</option></select>
</p>
<p><input id="ticket_submit" name="commit" type="submit" value="Create Ticket" /></p>
</form>
class TicketsController < ApplicationController
def show
@ticket = Ticket.find(params[:id])
# @comments = Comment.all
# @comment = @ticket.comments.build
end
def new
@ticket = ticketable.tickets.build
#@ticket = @person.tickets.build
end
def create
@ticketable = ticketable
@ticket = @ticketable.tickets.build(params[:ticket])
# @ticket = Ticket.new(params[:ticket])
# @user = current_user
if @ticket.save
redirect_to @ticket, :notice => 'Ticket was created successfully'
else
flash[:notice] = 'Ticket was not created Successfully.'
render = 'new'
end
end
def edit
@ticket = Ticket.find(params[:id])
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 ticketable
find_company || find_person || raise(ActiveRecord::RecordNotFound)
end
def find_company
(id = params[:company_id]) ? Company.find(id) : nil
end
def find_person
(id = params[:person_id]) ? Person.find(id) : nil
end
def find_user
(id = params[:user_id]) ? User.find(id) : nil
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