Is it possible in Ruby (2) and Rails (3.2) to update a selection of fields in a single command. For example, I need to update a set of fields in a hook, where all the names match. I end up with something like this
def set_address
assign_attributes(address1: subscription.subscriber.address1,
address2: subscription.subscriber.address2,
address3: subscription.subscriber.address3,
city: subscription.subscriber.city,
county: subscription.subscriber.county,
country_id: subscription.subscriber.country_id,
postcode: subscription.subscriber.postcode)
end
given that all the field names match across the two models is there an easier way to do this, or a way to group the fields together so that I can execute
def set_address
address = subscription.subscriber.address
end
Any advice appreciated
Aucun commentaire:
Enregistrer un commentaire