Яuбy / Говнокод #19836 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
before_create :build_client_info_attributes
def build_client_info_attributes
  CLIENT_INFO_ATTRIBUTES.each do |attr|
    eval("def #{attr}();return read_attribute(:#{attr}).present? ? read_attribute(:#{attr}) : subject.try(:owner).try(:#{attr});end;")
   end
   eval("def country_id;read_attribute(:country).present? ? read_attribute(:country) : subject.try(:owner).try(:country).try(:id);end;")
end

Шедевр метапрограммирования.

maxk maxk, (Updated )

Комментарии (3, +3)

Яuбy / Говнокод #19774 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
prepared_items = @cart.prepare_sort
    errors = []
    orders = []

    ActiveRecord::Base.transaction do
      address_create = create_new_address address_params if order_params[:address_attributes].present?

      prepared_items.each do |type, items|
        next unless items.present?

        user = current_user.class.name == 'User' ? { user_id: current_user.id } : { user_id: nil }

        case type
          when :order    then @order = Order.new(order_params.merge(user))
          when :preorder then @order = Order.new(order_params.merge(user.merge(status: 'preorder')))
          when :b_y      then @order = Order.new(order_params.merge(user.merge(delivery: 'pick_up', store_id: Settings.store.for_by)))
        end

        @order.is_mobile = mobile_device?
        @order.promo_code = @cart.promo_code
        @order.promotion = Promotion.for_line_items(@cart)

        good_promotion = Promotion.good_promotion_with_bonus(@cart)
        if good_promotion && @cart.used_promotion_discount > 0
          @order.bonus_promotion = good_promotion.promotion
          @order.stored_bonus_promotion_discount = @cart.used_promotion_discount
        end

        items.each{ |item| @order.add_line_item item }
        address_create.orders << @order if address_create.present?

        if @order.save
          orders << @order
        else
          errors += @order.errors.full_messages
        end
      # Are you fucking serious?
      end if errors.empty?

чувак спутал цикл и each с блоком, печалька. код из реального проекта

tribals tribals, (Updated )

Комментарии (4, +4)

Яuбy / Говнокод #19771 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
begin
        @project = Admin::Project.find(params[:project_id])
      rescue ActiveRecord::RecordNotFound => ex
        raise ActiveRecord::RecordNotFound, "project with id = #{params[:project_id]} not found"
      end

      begin
        user = Admin::User.find(params[:user_id])
      rescue ActiveRecord::RecordNotFound => ex
        raise ActiveRecord::RecordNotFound, "user with id = #{params[:user_id]} not found"
      end

strax strax, (Updated )

Комментарии (13, +13)

Яuбy / Говнокод #19765 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
def events_format(e)
  m = I18n.l e.event_start, :format=> '%m'
  m =  m.sub!(/^0/, "") if m[0] == "0"
  m_result = "#{I18n.l e.event_start, :format=> '%Y-%m-%d'}"
  return [m_result + " • " + e.name + " • " + e.try(:venue).try(:city).try(:name).to_s, e.id]
end

american_spy american_spy, (Updated )

Комментарии (1, +1)

Яuбy / Говнокод #19758 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
def self.any_value_to_boolean(val)
  val = (((val.is_a? String) and (val.downcase != 'false') and (val.downcase != 'no') and (val != '0')) \
    or ((val.is_a? Numeric) and (val != 0)))
  val
end

Привидение типов хендмейд. Найдено здесь https://github.com/Novator/Pandora
Вообще каждый из 21к строк дойстойна быть здесь

SqREL SqREL, (Updated )

Комментарии (12, +12)

Яuбy / Говнокод #19494 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
def show
      if (params[:id].scan(/-/).length == 1)
        redirect_to transfers_path(game_id: params[:game_id], period: 'days', start_date: params[:id] + '-01', end_date: Date.parse(params[:id] + '-01').end_of_month.strftime('%Y-%m-%d'))
        return
      end
      ...
    end

А всего лишь нужно было в действие show принимать дату

Sandwich Sandwich, (Updated )

Комментарии (1, +1)

Яuбy / Говнокод #19420 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
data = []
10000.times do |i|
  data.push ({ :shipper => 'ЗАО "НЕФТЕТРАНССЕРВИС" ' + i, :shipper_id => i })
end

Когда одного НЕФТЕТРАНССЕРВИСа просто мало...

SDK SDK, (Updated )

Комментарии (0)