Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jamesgecko/963281 to your computer and use it in GitHub Desktop.

Select an option

Save jamesgecko/963281 to your computer and use it in GitHub Desktop.
class SupportCallsController < ApplicationController
def new
@support_call = SupportCall.new
@customers = Customer.all
end
def create
@support_call = SupportCall.new(params[:support_call])
respond_to do |format|
if @support_call.save
format.html { redirect_to @support_call }
format.js
else
format.html { render :action => "new" }
format.js
end
end
end
def edit
@support_call = SupportCall.find(params[:id])
@customer = Customer.find(@support_call.customer_id)
@customers = Customer.all
end
def show
if session[:employee_first_name]
redirect_to :action => 'edit', :id => params[:id]
return
else
@support_call = SupportCall.find(params[:id])
@customer = Customer.find(@support_call.customer)
end
end
def update
@support_call = SupportCall.find(params[:id])
if @support_call.update_attributes(params[:support_call])
redirect_to @support_call, :notice => 'Call was sucessfully updated.'
else
render :action => 'edit'
end
end
end
class Customer < ActiveRecord::Base
validates :name, :presence => true
validates :address, :presence => true,
:length => { :minimum => 5 }
has_many :phone_numbers
has_many :support_calls
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
end
class SupportCall < ActiveRecord::Base
belongs_to :customer
belongs_to :employee
def self.find_from_customer_id(customer_id)
find :all, :conditions => ['customer_id = ?', "%#{customer_id}%"]
end
end
<%= form_for(@support_call) do |f| %>
<div class="field">
<%= f.label :customer %><br />
<%= select_tag "support_call[customer_id]", options_from_collection_for_select(@customers, "id", "name") %>
#User input from this dropdown box does not appear in the database. :-/
</div>
<div class="field">
<%= f.label :caller %><br />
<%= f.text_field :caller %>
</div>
<div class="field">
<%= f.label :phone_number %><br />
<%= f.text_field :phone_number %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :csr %><br />
<%= f.text_field :csr %>
</div>
<div class="textarea">
<%= f.label :problem %><br />
<%= f.text_area :problem, :cols => 30, :rows => 3 %>
</div>
<div class="textarea">
<%= f.label :answer %><br />
<%= f.text_area :answer, :cols => 30, :rows => 3 %>
</div>
<div class="checkbox">
<%= f.check_box :resolved %> <%= f.label :resolved %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment