diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index d44d99d..e4da98d 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -57,6 +57,6 @@ class ProductsController < ApplicationController private def product_params - params.require(:product).permit(:name, :price, :avatar, :category, :stock) + params.require(:product).permit(:name, :price, :avatar, :category, :stock, :calories) end end diff --git a/app/models/product.rb b/app/models/product.rb index b0ba8a1..45eef95 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -13,6 +13,7 @@ # avatar_updated_at :datetime # category :integer default("0") # stock :integer default("0"), not null +# calories :integer default("0"), not null // expressed in kcal # class Product < ActiveRecord::Base @@ -24,6 +25,7 @@ class Product < ActiveRecord::Base validates :name, presence: true validates :price_cents, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :stock, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :calories, numericality: { only_integer: true, :allow_nil => true, greater_than_or_equal_to: 0 } validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] } diff --git a/db/migrate/20150707162949_add_calories_to_products.rb b/db/migrate/20150707162949_add_calories_to_products.rb new file mode 100644 index 0000000..78e4c6a --- /dev/null +++ b/db/migrate/20150707162949_add_calories_to_products.rb @@ -0,0 +1,5 @@ +class AddCaloriesToProducts < ActiveRecord::Migration + def change + add_column :products, :calories, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index ffa911b..fdd48de 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: 20150630183223) do +ActiveRecord::Schema.define(version: 20150707162949) do create_table "order_items", force: :cascade do |t| t.integer "order_id" @@ -41,6 +41,7 @@ ActiveRecord::Schema.define(version: 20150630183223) do t.datetime "avatar_updated_at" t.integer "category", default: 0 t.integer "stock", default: 0, null: false + t.integer "calories" end create_table "users", force: :cascade do |t|