mardi 11 juillet 2017

what is the best way to implement the generic action of controller where different response generated based on the params

Below code are written in the controller action where we are generating a different action based on the action parameter and secondary we are only generating the xml response on the basis of different action parameters.It's not necessary that every case of action consist result tag as parent.It's vary between action to action.

doc = EncodeDecode.decode(request.raw_post)
action =  parse_xml(doc/'action')  if (doc/'action').first

#    action = 'fetch_thread_colors'
case action
when 'create_customer_profile'
  result = Customer::CustomerCrud.create_customer_profile(doc)
  render :xml => "<result>#{result}</result>"

when 'create_customer_payment_profile' 
  result = Customer::CustomerCrud.create_customer_payment_profile(doc)
  render :xml => "<result>#{result}</result>"

How we can achieve the best way to implement because My problem is that it's to big in term of line of codes I am having more than 300-350 cases in the switch block.Is there any way something I can achieve it using metaprogramming But we also need to consider the point for memory efficient.

Solutions should be efficient ,clean and optimized to implement.

Any object oriented approach also can help me out.

Aucun commentaire:

Enregistrer un commentaire