Making it more DRY

Is there a way to make this code more DRY?

Lineitem.content_columns.each do |column|       in_place_edit_for :lineitem, column.name       in_place_loader_for :lineitem, column.name   end

  Glcode.content_columns.each do |column|       in_place_edit_for :glcode, column.name       in_place_loader_for :glcode, column.name   end

  Request.content_columns.each do |column|       in_place_edit_for :request, column.name       in_place_loader_for :request, column.name   end

  Product.content_columns.each do |column|       in_place_edit_for :product, column.name       in_place_loader_for :product, column.name   end

sjgdev wrote:

Is there a way to make this code more DRY?

Lineitem.content_columns.each do |column|       in_place_edit_for :lineitem, column.name       in_place_loader_for :lineitem, column.name   end

  Glcode.content_columns.each do |column|       in_place_edit_for :glcode, column.name       in_place_loader_for :glcode, column.name   end

  Request.content_columns.each do |column|       in_place_edit_for :request, column.name       in_place_loader_for :request, column.name   end

  Product.content_columns.each do |column|       in_place_edit_for :product, column.name       in_place_loader_for :product, column.name   end    Off the top of my head, haven't tested it...

[Lineitem, GLcode, Request, Product].each do |model|   model.content_columns.each do |column|     in_place_edit_for model.to_s.downcase.to_sym, column.name     in_place_loader_for model.to_s.downcase.to_sym, column.name   end end

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Throw the below method in application.rb. Then you can just do

edit_all_columns :lineitem, :glcode, :request, :product

I didn't test it, but I'm pretty sure it ought to wok as is. If not, tweak it a bit.

def self.edit_all_columns(*class_names)   class_names.each do |c|     klass = Kernel.const_get c.to_s.camelize     klass.content_columns.each do |column|       in_place_edit_for c, column.name       in_place_loader_for c, column.name     end   end end

Pat Maddox wrote: