lundi 1 mai 2017

Rails how to find id by another attr?

I'm looking to create a callback where update a object if find a attribute different than id or name.

in this case if find the order_id.

someone know how to find the object based on another model id attribute?

class Order < ActiveRecord::Base
 after_update  :update_odata


  def update_odata
        order = Order.find_by_id(attributes['id'])
        od = Odata.find_by_id(attributes['order_id'])
        od.shipping_cost = order.shipping_cost
        od.shipping_method  = order.shipping_method
        od.status  = order.status
        od.feedback_id = order.feedback_id
        od.track_number  = order.track_number
        od.seller_name  = order.seller_name
        od.buyer_name  = order.buyer_name
       od.save

   end
end

Aucun commentaire:

Enregistrer un commentaire