parent
33dac2f989
commit
ba3b16cc2d
@ -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
|
||||
@ -0,0 +1,2 @@
|
||||
module ProductsHelper
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
class Product < ActiveRecord::Base
|
||||
end
|
||||
@ -0,0 +1,12 @@
|
||||
<ul>
|
||||
<% @products.each do |product| %>
|
||||
<li>
|
||||
<a href="<%= edit_product_path(product) %>">
|
||||
<%= product.name %>
|
||||
</a>
|
||||
<br/>
|
||||
<%= product.description %>
|
||||
<%= product %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
@ -0,0 +1,14 @@
|
||||
<form action="<%= products_path %>" method="POST">
|
||||
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
|
||||
<input
|
||||
type="text"
|
||||
name="product[name]"
|
||||
placeholder="Product Name"
|
||||
value=""><br/>
|
||||
<input
|
||||
type="text"
|
||||
name="product[description]"
|
||||
placeholder="Product Description"
|
||||
value=""><br/>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
@ -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
|
||||
@ -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
|
||||
Loading…
Reference in new issue