sql - How to dynamic update columns in Ruby on Rails -


i have array of desired columns edit (wich dynamic), this:

toedit = ["last_name_required", "email_required", "phone_required"] 

remember, dynamic can have phone. example:

toedit = ["phone_required"] 

i have model sql columns like:

last_name_required email_required phone_required 

those columns accept boolean values.

i want generate code edit columns array values parameters. this:

o = model.fist o.last_name_required = true o.phone_required = true o.save 

i've tried like:

o = model.first o.toedit[0] = true o.toedit[1] = true o.save 

but understand wrong because trying use string object.

i don't know what's appropriate syntax.

any ideas?

thanks

o = model.new toedit.each |key|   o.send "#{key}=".to_sym, true end o.save 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -