I am searching from quite a long time now and I cannot figure out how to create active record in rails with hash except particular key in the hash.
What I am currently doing is
ingre = {:name => "pepper", :std_qty => 2, :quantity => 20}
quantity = ingre[:quantity]
ingre.delete(:quantity)
ingredient = Ingredient.new(ingre)
ingredient.save!
I do not have quantity
column in my ingredients
table, there are only name
and std_qty
. and I don't want to use delete because it is not very concise way. I know that there is some way where in we can avoid key quantity while building the object ingredient
instead of deleting externally. can anyone tell me what it is
Aucun commentaire:
Enregistrer un commentaire