Skip to content

Instantly share code, notes, and snippets.

@delianides
Created May 30, 2014 17:51
Show Gist options
  • Save delianides/c7d869cf2fe065bc6aad to your computer and use it in GitHub Desktop.
Save delianides/c7d869cf2fe065bc6aad to your computer and use it in GitHub Desktop.
Rails Code
class Truck < ActiveRecord::Base
has_many :dumps, dependent: :destroy
validates :username, presence: true
validates :password, presence: true
validates :frequency, presence: true
validates :name, presence: true
attr_accessor :username, :password, :name, :description
after_create :schedule_truck_delivery
# def as_hash
# {
# username: self.username,
# password: self.password,
# host: self.host,
# port: self.port,
# output_dir: self.output,
# filename: self.filename
# }
# end
private
def schedule_truck_delivery
name = "truck-#{self.name}"
config = {}
config[:class] = "BackupDatabase"
config[:args] = id
config[:queue] = 'trucks'
config[:every] = ['1h', {first_in: 1.minute}]
config[:persist] = true
Resque.set_schedule(name, config)
end
end
class Api::V1::TrucksController < ApiController
def index
@trucks = Truck.all
respond_with :api, :v1, @truck
end
def show
@truck = Truck.find(params[:id])
respond_with :api, :v1, @truck
end
def create
@truck = Truck.create(truck_params)
respond_with :api, :v1, @truck
end
def update
#pending
end
def destroy
#pending
end
private
def truck_params
params.require(:truck).permit!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment