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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 11/2/06, sjgdev <sjgdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > endThrow 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Pat Maddox wrote:> On 11/2/06, sjgdev <sjgdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > 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 > endPat, your way of doing this worked beautifully. Thanks a lot! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---