Skip to content

Instantly share code, notes, and snippets.

@sub
Created February 22, 2011 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sub/839014 to your computer and use it in GitHub Desktop.
Save sub/839014 to your computer and use it in GitHub Desktop.
metodo create iniziale
def create
puts "NEW"
offer = Offer.find(params[:offer_id])
if params[:offer_id]
task = JSON.parse(params[:tasks])
unless task.nil?
task["active_gift"]=="on" ? active_gift = true : active_gift = false
task["active_gift"] = active_gift
active_gift = true if task["active_gift"]
task, gift = separate_gift(task)
if task.class == Hash and !task["id"].empty?
#and task.key? "id"
puts "UPDATE!"
task_id = task["id"]
new_task = Task.find(task_id)
new_task.update_attributes(task)
if active_gift
puts "GIFT CREATE"
delete_gift = Gift.find_by_task_id(task_id)
delete_gift.delete unless delete_gift.nil?
new_gift = Gift.new(gift)
new_task.gift = new_gift
new_task.save
else
puts "DISATTIVA GIFT!"
new_task.active_gift = false
new_task.gift.delete
new_task.save
elsif task.class == Array
puts "DELETE!"
Task.find(task.first).destroy
else
puts "NEWTASK"
task.delete("id")
new_task = Task.new(task)
new_task.service = offer.service
new_task.save
if active_gift
new_gift = Gift.new(gift)
new_task.gift = new_gift
else
new_task.has_gift = false
new_task.save
end
end
end
else
render :json => @service.to_ext_json(:success => @service.update_attributes(params[:service]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment