Class: ContactsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ContactsController
- Defined in:
- app/controllers/contacts_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#create ⇒ Object
POST customers/1/contacts POST customers/1/contacts.json.
-
#destroy ⇒ Object
DELETE customers/1/contacts/1 DELETE customers/1/contacts/1.json.
-
#index ⇒ Object
GET customers/1/contacts GET customers/1/contacts.json.
-
#show ⇒ Object
GET customers/1/contacts/1 GET customers/1/contacts/1.json.
-
#update ⇒ Object
PUT customers/1/contacts/1 PUT customers/1/contacts/1.json.
Methods included from SessionsHelper
#preferences_customer_type=, #preferences_customer_type?, #signed_in?, #signed_in_user, #store_location
Class Method Details
.select_departments ⇒ Object
21 22 23 |
# File 'app/controllers/contacts_controller.rb', line 21 def self.select_departments BusinessDepartment.all end |
Instance Method Details
#create ⇒ Object
POST customers/1/contacts POST customers/1/contacts.json
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/contacts_controller.rb', line 60 def create @customer = Customer.find(params[:customer_id]) @contact = @customer.contacts.build(params[:contact]) respond_to do |format| if @contact.save format.html { redirect_to([@contact.customer, @contact], :notice => 'Contact was successfully created.') } format.json { render :json => @contact, :status => :created, :location => [@contact.customer, @contact] } else format.html { render :action => "new" } format.json { render :json => @contact.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE customers/1/contacts/1 DELETE customers/1/contacts/1.json
94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/contacts_controller.rb', line 94 def destroy @customer = Customer.find(params[:customer_id]) @contact = @customer.contacts.find(params[:id]) @contact.destroy respond_to do |format| format.html { redirect_to customer_contacts_url(customer) } format.json { head :ok } end end |
#index ⇒ Object
GET customers/1/contacts GET customers/1/contacts.json
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/contacts_controller.rb', line 7 def index @sels = params["sels"] || [] @contacts = @customer.contacts.search_by_params(@contacts, params).paginate(page: params[:page], :per_page => 5) respond_to do |format| format.html # index.html.erb format.json do #@content = render_to_string( :template => "contacts/_list", :locals => { items: @customer.contacts }, :formats => :html, :layout => false) #render :json => @content, :content_type => "application/json" render :partial => "list", :locals => { items: @contacts, :layout => false }, :formats => :html, :layout => false end end end |
#show ⇒ Object
GET customers/1/contacts/1 GET customers/1/contacts/1.json
27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/contacts_controller.rb', line 27 def show @customer = Customer.find(params[:customer_id]) @contact = @customer.contacts.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render "show.html.erb", :layout => false } end end |
#update ⇒ Object
PUT customers/1/contacts/1 PUT customers/1/contacts/1.json
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/contacts_controller.rb', line 77 def update @customer = Customer.find(params[:customer_id]) @contact = @customer.contacts.find(params[:id]) respond_to do |format| if @contact.update_attributes(params[:contact]) format.html { redirect_to([@contact.customer, @contact], :notice => t('forms.update.sucess')) } format.json { head :ok } else format.html { render :action => "edit" } format.json { render :json => @contact.errors, :status => :unprocessable_entity } end end end |