-
-
Save remogatto/839055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
offer = Offer.find(params[:offer_id]) | |
if params[:offer_id] | |
task = JSON.parse(params[:tasks]) | |
unless task.nil? | |
# seleziona i parametri rispondenti alla RE active_(.*) | |
# in questo modo otterrai una lista "elems" di al max 3 elementi del tipo | |
# elems == ['active_gift', 'active_encoding', ...] | |
elems.each do |elem| | |
klass_name = elem.split('_')[1].capitalize | |
klass = eval klass_name | |
# a questo punto hai la classe klass che equivale a Gift, Encoding, etc. | |
task, elem_instance = klass.separate(task) | |
if task.class == Hash and !task["id"].empty? | |
task_id = task["id"] | |
new_task = Task.find(task_id) | |
new_task.update_attributes(task) | |
if task["active_#{elem}"] | |
delete_elem = klass.find_by_task_id(task_id) | |
delete_elem.delete unless delete_elem.nil? | |
new_task.send(elem, klass.new(elem_instance)) | |
new_task.save | |
else | |
... | |
elsif task.class == Array | |
... | |
else | |
... | |
if task["active_#{elem}"] | |
... | |
else | |
... | |
end | |
end | |
end | |
else | |
render :json => @service.to_ext_json(:success => @service.update_attributes(params[:service])) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment