Add the migrations, add the category to the form
This commit is contained in:
parent
1e0f04ada2
commit
e76a139205
10 changed files with 33 additions and 5 deletions
|
@ -39,7 +39,7 @@ class ProductsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def product_params
|
def product_params
|
||||||
params.require(:product).permit(:name, :price, :avatar)
|
params.require(:product).permit(:name, :price, :avatar, :category)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,12 +11,15 @@
|
||||||
# avatar_content_type :string(255)
|
# avatar_content_type :string(255)
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
|
# category :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
class Product < ActiveRecord::Base
|
class Product < ActiveRecord::Base
|
||||||
has_many :order_products
|
has_many :order_products
|
||||||
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium
|
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium
|
||||||
|
|
||||||
|
enum category: %w(food beverages other)
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
validates :price, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
|
||||||
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] },
|
validates_attachment :avatar, presence: true, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] },
|
||||||
|
|
|
@ -16,8 +16,13 @@
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# dagschotel :reference
|
# admin :boolean
|
||||||
# dagschotel_id :integer
|
# dagschotel_id :integer
|
||||||
|
# avatar_file_name :string(255)
|
||||||
|
# avatar_content_type :string(255)
|
||||||
|
# avatar_file_size :integer
|
||||||
|
# avatar_updated_at :datetime
|
||||||
|
# orders_count :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
<%= f.label :price %>
|
<%= f.label :price %>
|
||||||
<%= f.number_field :price, value: number_with_precision(f.object.price, precision: 2), class: 'form-control', placeholder: "0.00", step: :any %>
|
<%= f.number_field :price, value: number_with_precision(f.object.price, precision: 2), class: 'form-control', placeholder: "0.00", step: :any %>
|
||||||
|
|
||||||
|
<%= form_collection_select f, :category, Product.categories.keys, :to_s, :titlecase %>
|
||||||
|
|
||||||
<%= f.label :avatar %>
|
<%= f.label :avatar %>
|
||||||
<%= f.file_field :avatar %>
|
<%= f.file_field :avatar %>
|
||||||
|
|
||||||
|
|
5
db/migrate/20141210200008_add_category_to_products.rb
Normal file
5
db/migrate/20141210200008_add_category_to_products.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCategoryToProducts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :products, :category, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141210090544) do
|
ActiveRecord::Schema.define(version: 20141210200008) do
|
||||||
|
|
||||||
create_table "order_products", force: true do |t|
|
create_table "order_products", force: true do |t|
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -38,6 +38,7 @@ ActiveRecord::Schema.define(version: 20141210090544) do
|
||||||
t.string "avatar_content_type"
|
t.string "avatar_content_type"
|
||||||
t.integer "avatar_file_size"
|
t.integer "avatar_file_size"
|
||||||
t.datetime "avatar_updated_at"
|
t.datetime "avatar_updated_at"
|
||||||
|
t.integer "category", default: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: true do |t|
|
||||||
|
|
1
test/fixtures/products.yml
vendored
1
test/fixtures/products.yml
vendored
|
@ -11,6 +11,7 @@
|
||||||
# avatar_content_type :string(255)
|
# avatar_content_type :string(255)
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
|
# category :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
7
test/fixtures/users.yml
vendored
7
test/fixtures/users.yml
vendored
|
@ -16,8 +16,13 @@
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# dagschotel :reference
|
# admin :boolean
|
||||||
# dagschotel_id :integer
|
# dagschotel_id :integer
|
||||||
|
# avatar_file_name :string(255)
|
||||||
|
# avatar_content_type :string(255)
|
||||||
|
# avatar_file_size :integer
|
||||||
|
# avatar_updated_at :datetime
|
||||||
|
# orders_count :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# avatar_content_type :string(255)
|
# avatar_content_type :string(255)
|
||||||
# avatar_file_size :integer
|
# avatar_file_size :integer
|
||||||
# avatar_updated_at :datetime
|
# avatar_updated_at :datetime
|
||||||
|
# category :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
|
@ -16,8 +16,13 @@
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# dagschotel :reference
|
# admin :boolean
|
||||||
# dagschotel_id :integer
|
# dagschotel_id :integer
|
||||||
|
# avatar_file_name :string(255)
|
||||||
|
# avatar_content_type :string(255)
|
||||||
|
# avatar_file_size :integer
|
||||||
|
# avatar_updated_at :datetime
|
||||||
|
# orders_count :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
Loading…
Reference in a new issue