Product calories: DB migration + Model update + attribute permit
This commit is contained in:
parent
5a5fbdf1c9
commit
849d9ce04b
4 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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"] }
|
||||
|
|
5
db/migrate/20150707162949_add_calories_to_products.rb
Normal file
5
db/migrate/20150707162949_add_calories_to_products.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddCaloriesToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :products, :calories, :int
|
||||
end
|
||||
end
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue