Skip to content

Instantly share code, notes, and snippets.

@juliends
Created February 6, 2017 11:16
Show Gist options
  • Save juliends/2aba399e6214094d3a546b55d20f8ce7 to your computer and use it in GitHub Desktop.
Save juliends/2aba399e6214094d3a546b55d20f8ce7 to your computer and use it in GitHub Desktop.
Some refacto for new_catgory_integration
def update_or_create_expert_category(category_ids)
categories = Category.find(category_ids.reject {|x| x.empty?})
@expert.categories.each do |category|
unless categories.include? category
expert_category.destroy
end
unless @expert.categories.include? category
ExpertCategory.create(expert: @expert, category: category)
end
end
end
@db0sch
Copy link

db0sch commented Feb 6, 2017

i don't like putting some ruby code inside the reject parameter
categories = Category.find(category_ids.reject {|x| x.empty?})

I prefere something like:

ids = category_ids.reject {|x| x.empty?}
categories = Category.find(ids)

I think it's cleaner.

For the rest, ok, even though, I have the feeling we can make this clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment