diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000..3846b8e --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,22 @@ +class ProductsController < ApplicationController + def index + @products = Product.all + end + + def new + @transgression = Product.new + end + + def create + @transgression = Product.new(product_params) + + if @transgression.save + redirect_to products_path + else + render :new + end + end + def product_params + return params.require(:product).permit(:name, :description) + end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 0000000..ab5c42b --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000..077a819 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,2 @@ +class Product < ActiveRecord::Base +end diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000..b2fb71f --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,12 @@ + diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 0000000..e1ee3d6 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,14 @@ +
+ +
+
+ +
diff --git a/config/routes.rb b/config/routes.rb index 3f66539..1bb8ec6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :products # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20151029235418_create_products.rb b/db/migrate/20151029235418_create_products.rb new file mode 100644 index 0000000..2c9683e --- /dev/null +++ b/db/migrate/20151029235418_create_products.rb @@ -0,0 +1,10 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.string :name + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..05eee69 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# 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: 20151029235418) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "products", force: :cascade do |t| + t.string "name" + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end