- 1
- 2
- 3
- 4
- 5
def self.round_more(number)
new_number = number.round
new_number = new_number + 1 if new_number < number
return new_number
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
def self.round_more(number)
new_number = number.round
new_number = new_number + 1 if new_number < number
return new_number
end
про ceil мы и не слышали
0
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
skip_before_filter :verify_authenticity_token
protect_from_forgery unless: -> { request.format.json? }
...
end
0
def has_children_pages(id)
unless Page.where(:parent_id => id, :public => true).blank?
return true
end
return false
end
мне сказали, что этот проект php-шники писали
0
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. Не смог придумать ничего лучше
0
attachment.save ?
flash[:notice] = 'Attachment was successfully created.'
:
flash[:alert] = 'Error saving attachment!'
0
%a{href: new_user_session_path} Вход
link_to это слишко просто
0
errors[:please] « "fill one more field"
Ruby On Rails. Крутяк)
0
(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)
)
Просто одна строчка контроллера, для выборки данных для графика.
0
current_time = (DateTime.parse(DateTime.now.to_s)).strftime('%d.%m.%Y %H:%M:%S')
суровые трудовыебудни
0
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
Первый раз я видел такое два года назад, думал, что за это время что-то поменялось в людях, неа. А вы говорите индусы