bartime's People
bartime's Issues
openingtimeテーブルとshopテーブルのアソシエーション
openingtimeテーブルとshopテーブルのアソシエーションはできたが
値自体をどのように扱っていいのかわからない。
class ShopsController < ApplicationController
def show
@shops = Shop.all
end
def hasmanytest
@shoptest = Shop.find_by(name:'izakaya5')
# @shoptest = Shop.find(3)
# @shoptest = Shop.find_by(shop_id:'1')
end
end
<ul>
<% @shoptest.openingtimes.each do |tt|%>
<%= tt.sun_time = "1000"%>
<li><%= tt.sun_time %></li>
<% end %>
</ul>
<%= @shoptest.name %>
グルメサイトAPIを使う
日本の全エンジニアに捧ぐ!現在公開されているAPI一覧【2013年版】
サイト内でレストランで検索。
ぐるなびとBARNAVIがいいと思った。
まずは画像を引っ張ります。
scaffold
rails g scaffold Shop latitude:float langitude:float address:string name:string url:string sun_time:string mon_time:string tue_time:string web_time:string thu_time:string fri_time:string sta_time:string
Shopテーブル
Shopテーブル
を作成する。
- name
- url
- image
- tel
- place
- image
- sun_time
- mon_time
- tue_time
- web_time
- thu_time
- fri_time
- sta_time
ヘッダーを縦にする
営業時間の計算
デモで書いたrubyのコード
def which_week(week_num)
if week_num == 0
p "sun"
elsif week_num == 1
p "mon"
elsif week_num == 2
p "thu"
elsif week_num == 3
p "web"
elsif week_num == 4
p "moku"
elsif week_num == 5
p "fri"
elsif week_num == 6
p "sta"
end
end
def change_minute(open_time)
minute = open_time[0 ]+ open_time[1]
return minute
end
def change_sec(open_time)
sec = open_time[2] + open_time[3]
return sec
end
def change_start_min(open_time)
sec = open_time[4] + open_time[5]
return sec
end
def change_end_sec(open_time)
sec = open_time[6] + open_time[7]
return sec
end
Integer shop1_time_hour = "19"
shop1_time_sce = 30
shop2_time = "1832"
sh2_min = change_minute(shop2_time)
sh2_sec = change_sec(shop2_time)
shop2_time = "17300300"
sh2_min_st = change_minute(shop2_time)
sh2_sec_st = change_sec(shop2_time)
sh2_min_end = change_start_min(shop2_time)
sh2_sec_end = change_end_sec(shop2_time)
t1 = Time.now
# puts t1.tomorrow
puts t1
puts t1_year = t1.strftime("%Y")
puts t1_month = t1.strftime("%m")
puts t1_day = t1.strftime("%d")
puts t1_week = t1.strftime("%A")
puts t1_time = t1.strftime("%X")
shop_start_m = 6
p t1_month
t2 = Time.mktime(t1_year,t1_month,t1_day,shop1_time_hour,shop1_time_sce,12)
t3 = Time.mktime(t1_year,t1_month,t1_day,shop1_time_hour,sh2_min,sh2_sec)
t4_st = Time.mktime(t1_year,t1_month,t1_day,shop1_time_hour,sh2_min_st,sh2_sec_st)
t4_en = Time.mktime(t1_year,t1_month,t1_day,shop1_time_hour,sh2_min_end,sh2_sec_end)
#
# if t4_st > t4_en
#
# asu_time = t1.tomorrow
# t4_en = Time.mktime(t1_year,t1_month,t1_day,asu_time,sh2_min_end,sh2_sec_end)
# end
puts t1
puts t2
puts t3
puts t4_st
puts t4_en
if t2 > t1
puts "t2が大きい"
elsif t1 > t2
puts "t1が大きい"
end
出力
2015-11-23 10:01:34 +0900
2015
11
23
Monday
10:01:34
"11"
2015-11-23 10:01:34 +0900
2015-11-23 19:30:12 +0900
2015-11-23 19:18:32 +0900
2015-11-23 19:17:30 +0900
2015-11-23 19:03:00 +0900
t2が大きい
位置情報を表示する。
営業時間データーベース
rails c
weekt = OpenTime.new(sun_time: "19002300", mon_time: "19002330",thu_time: "18002330",web_time:17002200,thu_time:18002200,fri_time:19002000,sta_time:18002200)
コンソールでOpenTImeモデルを作成する。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.