Mistři v programování na #hovnokod

Ruby #313

# Work fine only on call with has_many association
def self.new_from_params options
  new_rule = Rule.new
  return nil if new_rule.project_id.nil?

  rule = Rule.find_by_id options[:rule_id]
  if rule.nil? or (new_rule.project.id != rule.project.id)
    rule = Rule.new
  end

  new_rule.rule_id = options[:rule_id]
  new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
  new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
  new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
  new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
  new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
  new_rule.search = options[:search].presence || rule.search.presence
  new_rule.period_start = options[:period_start].presence || rule.period_start.presence
  new_rule.period_end = options[:period_end].presence || rule.period_end.presence

  new_rule
 end

HovnoKod,