Skip to content

Commit 1f3d15e

Browse files
- Added model and migration for diamonds
- Added routes and controller actions
1 parent fc19738 commit 1f3d15e

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class DiamondsController < ApplicationController
2+
def index
3+
@diamonds = Diamond.all
4+
render json: {status: :ok, data: @diamonds}
5+
end
6+
7+
def show
8+
end
9+
10+
def search
11+
end
12+
end

app/models/application_record.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end

app/models/diamond.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Diamond < ApplicationRecord
2+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Rails.application.routes.draw do
2+
resources :diamonds
3+
24
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
35
root 'application#index'
46
get '*path', to: 'application#index'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CreateDiamonds < ActiveRecord::Migration[5.1]
2+
def change
3+
create_table :diamonds do |t|
4+
t.string :shape
5+
t.decimal :weight
6+
t.string :color
7+
t.string :clarity
8+
t.decimal :length
9+
t.decimal :width
10+
t.string :lab
11+
t.decimal :price
12+
t.string :polish
13+
14+
t.timestamps
15+
end
16+
end
17+
end

db/schema.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# Note that this schema.rb definition is the authoritative source for your
6+
# database schema. If you need to create the application database on another
7+
# system, you should be using db:schema:load, not running all the migrations
8+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9+
# you'll amass, the slower it'll run and the greater likelihood for issues).
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 20180112082948) do
14+
15+
create_table "diamonds", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
16+
t.string "shape"
17+
t.decimal "weight", precision: 10
18+
t.string "color"
19+
t.string "clarity"
20+
t.decimal "length", precision: 10
21+
t.decimal "width", precision: 10
22+
t.string "lab"
23+
t.decimal "price", precision: 10
24+
t.string "polish"
25+
t.datetime "created_at", null: false
26+
t.datetime "updated_at", null: false
27+
end
28+
29+
end

0 commit comments

Comments
 (0)