瀏覽代碼

Add very basic pokemon management

Andrew Swistak 7 年之前
父節點
當前提交
8163cf131e

+ 2 - 0
app/models/pokemon.rb

@@ -0,0 +1,2 @@
+class Pokemon < ApplicationRecord
+end

+ 11 - 0
app/views/pokemon/index.haml

@@ -0,0 +1,11 @@
+= link_to "Create New Pokemon", new_pokemon_path
+%br
+= link_to "Upload New Pokemon", new_pokemon_path
+%br
+%br
+%table
+  %tbody
+    - @pokemon.each do |pokemon|
+      %tr
+        %td= link_to pokemon.nickname, pokemon
+

+ 9 - 0
app/views/pokemon/new.haml

@@ -0,0 +1,9 @@
+= form_for @pokemon do |f|
+  = f.hidden_field :id
+
+  %h2 New Pokemon
+
+  = f.select :pokedex_number, options_for_select(1..802)
+  = f.text_field :nickname
+
+  = submit_tag 'Save'

+ 7 - 0
app/views/pokemon/show.haml

@@ -0,0 +1,7 @@
+= @pokemon.pokedex_number
+%br
+= @pokemon.nickname
+%br
+%br
+= link_to "Delete this Pokemon", pokemon_path(@pokemon), method: :delete
+= link_to "Back", pokemon_index_path

+ 4 - 0
config/routes.rb

@@ -1,3 +1,7 @@
 Rails.application.routes.draw do
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+
+  root to: "pokemon#index"
+
+  resources :pokemon
 end

+ 12 - 0
db/migrate/20181228215350_create_pokemon.rb

@@ -0,0 +1,12 @@
+class CreatePokemon < ActiveRecord::Migration[5.2]
+  def change
+    create_table :pokemon do |t|
+      t.integer :pokedex_number, null: false, unsigned: true
+      t.string :nickname
+      t.binary :raw_nickname
+      t.binary :raw_pokemon
+
+      t.timestamps
+    end
+  end
+end

+ 27 - 0
db/schema.rb

@@ -0,0 +1,27 @@
+# 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: 2018_12_28_215350) do
+
+  # These are extensions that must be enabled in order to support this database
+  enable_extension "plpgsql"
+
+  create_table "pokemon", force: :cascade do |t|
+    t.integer "pokedex_number", null: false
+    t.string "nickname"
+    t.binary "raw_nickname"
+    t.binary "raw_pokemon"
+    t.datetime "created_at", null: false
+    t.datetime "updated_at", null: false
+  end
+
+end