Ruby on Rails Thursday, September 26, 2019

I'm not sure I understand what's the problem, where exactly do you have doubts?

I'd suggest you first refactor that super ugly nested loops and ifs:
- remove the unnecesarry if's
    DdCategory.all.each do |category|
      # If the Category is active, build it
      if category.is_active?

can't you handle that is_active? with a scope?

- the blocks for category.dd_items and subcategory.dd_items looks almost the same, I think you can reuse some code there

- move complex logic to other methods to clean that up, like:

                    item.dd_subitems.each do |subitem|
                      newitem.dd_detail_subitems.create!(dd_detail_item_id: newitem.id, title: subitem.title, has_check: subitem.has_check, has_value: subitem.has_value, has_note: subitem.has_note, item_check: subitem.item_check, item_value: subitem.item_value, item_note: subitem.item_note)
                    end

could be a method on newitem like "add_subitem_from(subitem)" that does that create but you'll have less clutter to simplify your logic to understand it better


El jue., 26 sept. 2019 a las 16:01, John Sanderbeck (<bandor535@gmail.com>) escribió:

Another thing to note is I am also only doing an Edit of the data as the records already have been created and are not allowed to be destroyed.

John 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/56b5ef26-e7ed-45a8-b346-b39c45edca0f%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcDL%2Bu4RcvNAEOdAV0q44dnD6OFOJ2BXT%2BoFxhKiyPOuBw%40mail.gmail.com.

No comments:

Post a Comment