Comments (8)
rails generate model Open_time shop_id:string sun_time:string mon_time:string tue_time:string web_time:string thu_time:string fri_time:string sta_time:string
モデル名にアンダーバーは入れるのはよくない。
なので一度
1006 rails destroy model OpenTime new
1007 rake db:migrate
1008 rails destroy model Open_Times new
1009 rails destroy model OpenTimes new
1010 rails destroy model Open_Time
1011 rails destroy model Open_Times
削除
from bartime.
rails generate model Openingtime shop_id:string sun_time:string mon_time:string tue_time:string web_time:string thu_time:string fri_time:string sta_time:string
とする
Open_time
が
Openingtime
に変更
from bartime.
weekt = Openingtime.new(sun_time: "19002300", mon_time: "19002330",tue_time: "18002330",web_time:17002200,thu_time:18002200,fri_time:19002000,sta_time:18002200)
weekt.save
で新規データ作成
というかcreate使えばよくない?
Openingtime.create(sun_time: "19002300", mon_time: "19002330",tue_time: "18002330",web_time:17002200,thu_time:18002200,fri_time:19002000,sta_time:18002200)
from bartime.
時間を表示するhtml.erbをここにメモ
<ul>
<% @opentimes.each do |opentime| %>
<li>
<%= opentime.sun_time %>
</li>
<% end %>
</ul>
<%= Time.now%>
from bartime.
rails generate model Opentime sun_time:string mon_time:string tue_time:string web_time:string thu_time:string fri_time:string sta_time:string
shop_id:string はアソシエーションと競合するのでやめよう。てかモデルの生成時に買ってにidつくから
from bartime.
Opentime.create(sun_time: "19002300", mon_time: "19002330",tue_time: "18002330",web_time:17002200,thu_time:18002200,fri_time:19002000,sta_time:18002200)
from bartime.
diff --git a/app/assets/stylesheets/shops.css.scss b/app/assets/stylesheets/shops.css.scss
index edfa885..d30fe6c 100644
--- a/app/assets/stylesheets/shops.css.scss
+++ b/app/assets/stylesheets/shops.css.scss
@@ -2,6 +2,6 @@
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.show_image{
- width: 20px;
- height: 20px;
+ width: 200px;
+ height: 200px;
}
diff --git a/app/controllers/open_time_controller.rb b/app/controllers/open_time_controller.rb
index f0c9bd6..05d3f74 100644
--- a/app/controllers/open_time_controller.rb
+++ b/app/controllers/open_time_controller.rb
@@ -1,6 +1,5 @@
class OpenTimeController < ApplicationController
def belongs
- @opentimes = OpenTime.all
+ @opentimes = Openingtime.all
end
-
end
diff --git a/app/controllers/shops_controller.rb b/app/controllers/shops_controller.rb
index 43cb609..c921d5a 100644
--- a/app/controllers/shops_controller.rb
+++ b/app/controllers/shops_controller.rb
@@ -3,8 +3,12 @@ class ShopsController < ApplicationController
@shops = Shop.all
end
- def belongs
- @opentimes = OpenTime.all
+ def hasmanytest
+ @shoptest = Shop.find_by(name:'izakaya5')
+ # @shoptest = Shop.find(3)
+ # @shoptest = Shop.find_by(shop_id:'1')
+
end
+
end
diff --git a/app/models/open_time.rb b/app/models/open_time.rb
deleted file mode 100644
index ab1db6c..0000000
--- a/app/models/open_time.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class OpenTime < ActiveRecord::Base
- belongs_to :shop
-end
diff --git a/app/models/shop.rb b/app/models/shop.rb
index be991a2..c9ff8e9 100644
--- a/app/models/shop.rb
+++ b/app/models/shop.rb
@@ -1,2 +1,3 @@
class Shop < ActiveRecord::Base
+ has_many :openingtimes
end
diff --git a/app/views/open_time/belongs.html.erb b/app/views/open_time/belongs.html.erb
index f9ca1d3..5a59ad7 100644
--- a/app/views/open_time/belongs.html.erb
+++ b/app/views/open_time/belongs.html.erb
@@ -1,3 +1,14 @@
-<% @opentimes.each do |opentime| %>
-<%= opentime.sun_time %>
-<% end %>
+<ul>
+ <% @opentimes.each do |opentime| %>
+ <li>
+ <%= opentime.sun_time %>sun_time<br>
+ <%= opentime.mon_time %>mon_time<br>
+ <%= opentime.tue_time %>tue_time<br>
+ <%= opentime.web_time %>web_time<br>
+ <%= opentime.thu_time %>thu_time<br>
+ <%= opentime.fri_time %>fri_time<br>
+ <%= opentime.sta_time %>sta_time<br>
+ </li>
+ <% end %>
+</ul>
+<%= Time.now%>
diff --git a/app/views/open_time/new.html.erb b/app/views/open_time/new.html.erb
index d9ace54..148738b 100644
--- a/app/views/open_time/new.html.erb
+++ b/app/views/open_time/new.html.erb
@@ -1,5 +1,3 @@
-<h1>OpenTime#new</h1>
-
-
-
-<p>Find me in app/views/open_time/new.html.erb</p>
+<%= @wtime.each do |hoge| %>
+<%= hoge.name%>
+<% end %>
diff --git a/app/views/shops/show.html.erb b/app/views/shops/show.html.erb
index 4bc1e0e..1096f50 100644
--- a/app/views/shops/show.html.erb
+++ b/app/views/shops/show.html.erb
@@ -11,6 +11,5 @@
<%= link_to "ホームページ",shop.url_home %>
<% end %>
</li>
-
<% end -%>
</ul>
diff --git a/config/routes.rb b/config/routes.rb
index bfd4c7d..5fb16c2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -2,6 +2,7 @@ BarOpeningHoursAizu::Application.routes.draw do
get "open_time/new"
get "open_time/belongs"
+ get "shops/hasmanytest"
get "shops/new"
root 'static_page#home'
match '/help', to: 'static_page#help', via: 'get'
diff --git a/db/development.sqlite3 b/db/development.sqlite3
index 0f7bcee..bb40c1f 100644
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ
diff --git a/db/migrate/20151122083233_create_open_times.rb b/db/migrate/20151122083233_create_open_times.rb
deleted file mode 100644
index ca38f3d..0000000
--- a/db/migrate/20151122083233_create_open_times.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-class CreateOpenTimes < ActiveRecord::Migration
- def change
- create_table :open_times do |t|
- t.string :shop_id
- t.string :sun_time
- t.string :mon_time
- t.string :tue_time
- t.string :web_time
- t.string :thu_time
- t.string :fri_time
- t.string :sta_time
-
- t.timestamps
- end
- end
-end
diff --git a/db/schema.rb b/db/schema.rb
index 4984a2c..142a6ca 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20151122083233) do
+ActiveRecord::Schema.define(version: 20151123071011) do
create_table "open_times", force: true do |t|
t.string "shop_id"
@@ -26,6 +26,18 @@ ActiveRecord::Schema.define(version: 20151122083233) do
t.datetime "updated_at"
end
+ create_table "openingtimes", force: true do |t|
+ t.string "sun_time"
+ t.string "mon_time"
+ t.string "tue_time"
+ t.string "web_time"
+ t.string "thu_time"
+ t.string "fri_time"
+ t.string "sta_time"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "shops", force: true do |t|
t.string "name"
t.string "url_home"
diff --git a/test/fixtures/open_times.yml b/test/fixtures/open_times.yml
deleted file mode 100644
index 7dafa91..0000000
--- a/test/fixtures/open_times.yml
+++ /dev/null
@@ -1,21 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
-
-one:
- shop_id: MyString
- sun_time: MyString
- mon_time: MyString
- tue_time: MyString
- web_time: MyString
- thu_time: MyString
- fri_time: MyString
- sta_time: MyString
-
-two:
- shop_id: MyString
- sun_time: MyString
- mon_time: MyString
- tue_time: MyString
- web_time: MyString
- thu_time: MyString
- fri_time: MyString
- sta_time: MyString
diff --git a/test/models/open_time_test.rb b/test/models/open_time_test.rb
deleted file mode 100644
index 9420971..0000000
--- a/test/models/open_time_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class OpenTimeTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
from bartime.
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151123144654) do
create_table "open_times", force: true do |t|
t.string "shop_id"
t.string "sun_time"
t.string "mon_time"
t.string "tue_time"
t.string "web_time"
t.string "thu_time"
t.string "fri_time"
t.string "sta_time"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "opentimes", force: true do |t|
t.string "sun_time"
t.string "mon_time"
t.string "tue_time"
t.string "web_time"
t.string "thu_time"
t.string "fri_time"
t.string "sta_time"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "shops", force: true do |t|
t.string "name"
t.string "url_home"
t.string "url_outsite"
t.string "memo"
t.string "shop_image"
t.datetime "created_at"
t.datetime "updated_at"
end
end
from bartime.
Related Issues (8)
- グルメサイトAPIを使う
- openingtimeテーブルとshopテーブルのアソシエーション HOT 2
- 営業時間の計算
- 位置情報を表示する。
- Shopテーブル HOT 12
- ヘッダーを縦にする
- scaffold HOT 2
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.
from bartime.