- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 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#
...
Почему никогда нельзя нанимать индусских программистов. Выдержки из избранного.
heyzea1 23.01.2015 11:05 # 0
deadleaves1985 23.01.2015 11:48 # 0
Vasiliy 23.01.2015 19:42 # 0
inkanus-gray 23.01.2015 22:33 # +2
Vasiliy 25.01.2015 18:12 # 0
inkanus-gray 27.01.2015 14:12 # +1
Vasiliy 27.01.2015 19:59 # 0
Stallman 03.09.2017 14:06 # +3