1. Ruby / Говнокод #17576

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    def contract_params
      if params[:contract][:contract_type].to_i == 1
        field = :contractor_id
      else
        field = :legal_entity_id
      end
      params.require(:contract).permit(
          :contract_type,
          :paid_expectation,
          field
      )
    end

    Much strong, very params.

    FancyDancy, 04 Февраля 2015

    Комментарии (1)
  2. Ruby / Говнокод #17575

    −126

    1. 1
    2. 2
    = simple_fields_for @med_program_template do |f|
      - form ||= f # Страшное коварство

    FancyDancy, 04 Февраля 2015

    Комментарии (49)
  3. Ruby / Говнокод #17560

    −141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    # GET /med_programs/1/edit
      def edit
        @med_program = MedProgram.includes(:appeal, :template).find(params[:id])
        next_step_path = next_step_appeal_path(@med_program.appeal_id)
        # TODO: flash.keep ?
        case true
          when @med_program.appeal.kit_not_found?
            redirect_to @med_program.appeal
          when @med_program.appeal.new?
            # Just render edit view
          when @med_program.appeal.verify_person?
            redirect_to edit_person_path(@med_program.appeal.person_id, :back_url => next_step_path)
            return # для наглядности
          when @med_program.appeal.create_user?
            if @med_program.appeal.person.user_id
              path = edit_user_path(@med_program.appeal.person.user_id, :back_url => next_step_path)
            else
              path = new_user_path(:person_id => @med_program.appeal.person_id, :back_url => next_step_path)
            end
            redirect_to path
            return # для наглядности
          when @med_program.appeal.add_doctor?
            redirect_to add_doctor_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.create_user_doctor?
            if @med_program.doctor.person.user_id
              path = edit_user_path(@med_program.doctor.person.user_id, :back_url => next_step_path)
            else
              path = new_user_path(:person_id => @med_program.doctor.person_id, :back_url => next_step_path)
            end
            redirect_to path
            return # для наглядности
          when @med_program.appeal.add_contractor?
            redirect_to add_contractor_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.input_settings?
            redirect_to set_settings_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.pick_specialists?
            redirect_to select_specialists_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.pick_operators?
            redirect_to select_operators_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.read_informed_consent?
            redirect_to informed_consent_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.sign_contract?
            redirect_to sign_contract_med_program_path(@med_program.id)
            return # для наглядности
          else
            redirect_to @med_program
        end
      end

    Самый наглядный код в мире

    FancyDancy, 02 Февраля 2015

    Комментарии (3)
  4. Ruby / Говнокод #17559

    −157

    1. 1
    patient_id = MedProgram.where(:id => params[:med_program_id]).limit(1).pluck(:patient_id).first

    FancyDancy, 02 Февраля 2015

    Комментарии (1)
  5. Ruby / Говнокод #17552

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    def append_card(cards, new_card)
          if cards.nil?
            new_card == GameEvent::YELLOW_CARD ? 'yellow' : 'red'
          elsif cards == 'yellow'
            new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
          elsif cards == 'red'
            new_card == GameEvent::YELLOW_CARD ? 'yellow_red' : 'red'
          elsif cards == 'two_yellow'
            'two_yellow'
          elsif cards == 'yellow_red'
            new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
          end 
        end

    ничего особенного, просто подсчитываем, какую карточку получил игрок футбольной команды.
    а я думал, что что-то понимаю в футболе... я никогда в жизни так не ошибался

    iHateBidlocod, 31 Января 2015

    Комментарии (4)
  6. Ruby / Говнокод #17498

    −89

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    # Да, да, захардкоженные id! 
    # .where(id: [id_arrays]) ? Не, не слышал
    @cities = [52, 21, 9, 18, 196, 27, 106, 4, 40, 71].collect { |c| City.find(c) }
    
    # Это все в одном экшене, ага.
        session[:latitude] = params[:my_latitude]
        session[:longitude] = params[:my_longitude]
        session[:my_address] = params[:my_address]
        session[:fuel] = params[:fuel][:fuel_id]
        session[:range] = params[:station][:range]
    
    # А потом кто-нибудь развернет базу из бэкапа без сохранения первичных ключей и все перестанет работать.
    @fuels = Fuel.where(:id=>[1, 2, 3, 5])
    
    # Типичный экшен
        session[:view_sub_page] = action_name
        id = params[:station_chain].split("-")
        s_id = id[id.size - 2]
        station = Station.where(:id=>s_id)
        @fuels_level = AppUtils.calculate_price(station)
        @prices = station.last.prices.order("created_at").group_by { |item| item.fuel_id }
        @fuel_id = id[id.size - 1].to_i
        @station_lists = Station.get_station_detail_map(station, @fuels_level, @fuel_id, @prices)
        @station = station.last
        @station_logo = ''
        @station_logo_chain = ManageStationChain.where(:brand_id=>@station.brand_id).last
        @station_logo = PromoLogo.find_by_station_id(@station.id)
        @end = @station.address
        @fuels = Fuel.where(:id=>[1, 2, 3, 5])
        @sub_station = ""
        @cities = Station.get_static_cities()
    
    # Какие еще Rails, у меня свой лисопед
      def City.find_by_name(name)
        city = City.where("name = ?", name).first
    
        if city.nil?
          city = City.new
          city.name = name
          city.save
        end
        return city
      end
    
    # Именно так, в одну строчку. station.open_time и close_time - типа :time в базе
    if !station.open_time.nil? and !station.close_time.nil? and (Time.parse(station.open_time.to_s)...Time.parse(station.close_time.to_s)).cover?(Time.now.utc.change(year: 2000, month: 1, day: 1, hour: Time.now.hour, min: Time.now.min, second: 0)) == false
            return "PRICE_LEVEL_CLOSE"
      end
    
    # Компьютер купил, программировать не купил
    # В таблице Points - тысячи записей
    def get_points
        points = Points.all
        render json: {:success => true, :data => {:points => points.as_json(:only => [:action, :points, :points_new])}} and return
      end
    
    # И под занавес - код логина
    # Гемы? Devise? OAuth? А чой энта?
    def login
        register = false
        url = "https://graph.facebook.com/me/?access_token="+params[:facebook_token]
        uri = URI.parse(url)
        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true
        request = Net::HTTP::Get.new(uri.path + "?" + uri.query)
        response = http.request(request)
        if response.code == "200"
          facebook_response = JSON.parse(response.body)
          user = User.where("facebook_id = ?", facebook_response["id"]).first
          if !user
            user = User.new
            user.facebook_id = facebook_response["id"]
            user.nick = facebook_response["username"]
            user.email = facebook_response["email"]
            register = true
          end
          user.email = facebook_response["email"]
          user.generate_token
          user.save
          if register == true
            history = History.new
            history.user = user
            points = Points.where(:action => "REGISTER").first
            history.points_action = points
            history.points = points.points
            user.points+=points.points
            user.save
            history.save
          end
          logger.debug("Calculating point");
          points = Points.where('action != ?', 'FACEBOOK_INVITES')
          logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
          logger.debug("Testing for points");
          logger.debug(points.as_json(:only => [:action, :points]))
          logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
          if user.disabled == true
            render json: {:success => false, :error => {:message => "Invalid facebook token", :error_code => "INVALID_TOKEN"}}, status: :unauthorized and return
          else
            render json: {:success => true, :data => {:auth_token => user.auth_token, :points => points.as_json(:only => [:action, :points])}} and return# 
    ...

    Почему никогда нельзя нанимать индусских программистов. Выдержки из избранного.

    deadleaves1985, 23 Января 2015

    Комментарии (8)
  7. Ruby / Говнокод #17095

    −82

    1. 1
    2. 2
    3. 3
    4. 4
    @old_article_purchase.old_article.warehouse_placement = '102A1'
    if @old_article_purchase.old_article.valid?
       @old_article_purchase.old_article.save   
     end

    andrejlr, 12 Ноября 2014

    Комментарии (2)
  8. Ruby / Говнокод #16813

    −93

    1. 1
    deals = Deal.joins(:deal_locations).select("deals.id, (SELECT array(SELECT category_id FROM deal_categories WHERE deal_id = deals.id ORDER BY category_id ASC)) AS category, deals.start_date, deals.end_date, deals.address, deals.theme, deals.alias, deals.metro, deals.district, deals.discount, deals.coupon_count, deals.issued_coupons, deals.main_image, count(*) OVER() AS total_count, trunc(abs(extract(epoch FROM age(deals.end_date, clock_timestamp()))/86400)) AS days_left").where("deal_locations.deal_id = deals.id AND deal_locations.location_id = ? AND deals.category_id IN (#{categories[0...-2]}) AND deals.id NOT IN (#{ex_deals.map{|e| e}.join(", ")})", params[:location].to_i).active.in_stock.limit(limit).offset(offset).order("deals.start_date desc")

    Rails. Да, да, активрекорд, я помню о тебе.

    adastreamer, 07 Октября 2014

    Комментарии (29)
  9. Ruby / Говнокод #16324

    −151

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    def get_team_choices_with_index
        school_ids = params[:school_id].split(",")
        @index = params[:index]
    
        @teams_array = Array.new
        school_ids.each do |s|
          next if s.eql? "0"
          School.find(s).teams.each do |t|
            @teams_array << t
          end
        end
    
        @teams_array.flatten!
        @teams_array
      end

    А должно быть что-то вроде
    @teams_array = Team.where(school_id: school_ids)

    dj_Andreus, 14 Июля 2014

    Комментарии (1)
  10. Ruby / Говнокод #16072

    −136

    1. 1
    2. 2
    3. 3
    4. 4
    it 'traders email should be nil' do
       trader = FactoryGirl.create(:trader, :email => nil)
       trader.email.should be nil
    end

    captain obvious test

    andrejlr, 28 Мая 2014

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