Skip to content

Instantly share code, notes, and snippets.

@kmelkon
Last active December 21, 2015 17:09
Show Gist options
  • Save kmelkon/6338620 to your computer and use it in GitHub Desktop.
Save kmelkon/6338620 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: deals
#
# id :integer not null, primary key
# company_id :integer
# name :text
# background :text
# currency :text
# value :float
# offer :text
# deal_category_id :integer
# deal_status_id :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# status :boolean
# state :string(255)
#
class DealsController < ApplicationController
def index
@deals=Deal.all
@companies = Company.all
end
def create
@deal=Deal.new(params[:deal])
@deal.company_id = params[:company_id]
@company = Company.find_by_id(@deal.company_id)
flash[:success] = 'Deal Created!'
respond_to do |format|
if @deal.save
format.html { render controller: "companies" , action: "show" }
format.js
else
render :json => { }, status => 500
end
end
end
def status
@deal = Deal.find_by_id(params[:deal_id])
@deal.update_attribute(:state, params[:state])
respond_to do |format|
format.js
end
end
def edit
@deal = Deal.find(params[:id])
end
def update
@deal = Deal.find(params[:id])
@deal.update_attributes!(params[:deal])
redirect_to :action => 'index'
end
def destroy
@deals = Deal.all
params[:deal_ids].each do |deal|
deal_id = deal
d = Deal.find_by_id(deal_id)
d.destroy
respond_to do |format|
format.js
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment