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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  skip_before_filter :verify_authenticity_token
  protect_from_forgery unless: -> { request.format.json? }

  ...
end

fLa fLa, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
def has_children_pages(id)
  unless Page.where(:parent_id => id, :public => true).blank?      
    return true
  end      
  return false
end

мне сказали, что этот проект php-шники писали

Fuelen Fuelen, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
def result object, method = :save
  method = :destroy if caller[0][/`.*'/][1..-2] == 'destroy'
  if object.send method
    def object.to_json(options) ''; end
    respond_with object
  else
    raise UnprocessableEntityError.new(object.errors.full_messages.join(', '))
  end
end

Метод в базовом классе апишки. Надо чтобы на POST возвращалось 201, на DELETE 204 и т.д. respond_with делает это сам, но он же возвращает весь объект сериализованный чего не хочется т.к. для вертания сериализованных объектов используется jbuilder. Не смог придумать ничего лучше

FlySnake FlySnake, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
(Time.now.to_date-1.year .. Time.now.to_date).
map{|x|  {x.to_time.to_i =>0} }.
reduce(Hash.new, :merge).merge(
	TrackLocation.unscoped.joins(:track).where(track: @user.all_tracks).
	where("tracks.start_time < ? AND tracks.start_time > ?", Time.now.to_date, Time.now.to_date-1.year).
	group(:start_time).maximum(:distance).
	map{|x,v| {x.to_date.to_time.to_i => v.round(3)} if v}.compact.
	reduce(Hash.new, :merge)
)

Просто одна строчка контроллера, для выборки данных для графика.

IOException IOException, (Updated )

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

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

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
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
def update
    error = false
    if params[:geografic].present? && ((params[:geografic] & IsoCountryCodes.all.map{|c|c.alpha2.downcase}) == params[:geografic])
      current_user.profile.geografic = params[:geografic]
    else
      error = true
      flash[:alert] ||= ''
      flash[:alert] << "Need select countries. "
    end
    begin
      current_user.profile.sectors_of_interests = Sector.find(params[:sectors_of_interests])
    rescue
      error = true
      flash[:alert] ||= ''
      flash[:alert] << 'Can not find sectors. '
    end
    if params[:profession_id].present? && profession = Profession.find(params[:profession_id])
      current_user.profile.update_attribute(:profession_id, params[:profession_id])
    else
      error = true
      flash[:alert] ||= ''
      flash[:alert] << 'Can not find profession. '
    end
    if ['cn', 'gb'].include?(params[:language_iso])
      current_user.profile.update_attribute(:country_iso, params[:language_iso])
    else
      error = true
      flash[:alert] ||= ''
      flash[:alert] << "Need select language. "
    end
    if params[:telephone].present?
      current_user.profile.update_attribute(:phone, params[:telephone])
    else
      error = true
      flash[:alert] ||= ''
      flash[:alert] << "Need input phone number. "
    end

    require_additional_info = (current_user.geografic.blank? || current_user.sectors_of_interests.blank? || current_user.profession.blank? || current_user.phone.blank?)
    if require_additional_info || error
      redirect_to user_path(current_user) and return
    else
      redirect_to root_path
    end
  end

Первый раз я видел такое два года назад, думал, что за это время что-то поменялось в людях, неа. А вы говорите индусы

Ignat_Z Ignat_Z, (Updated )

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