diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 84a2e57..f1ff050 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,4 +1,5 @@ class OrdersController < ApplicationController + include OrdersHelper def new @user = User.find(params[:user_id]) @@ -17,7 +18,7 @@ class OrdersController < ApplicationController @products = Product.all @order_products = @order.order_products if @order.save - flash[:success] = "Ordered things! Get your stuff!" + flash[:success] = order_to_sentence(@order) + " ordered. Enjoy it!" redirect_to root_path else render 'new' diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 65b79e7..ec7b916 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -14,6 +14,7 @@ class ProductsController < ApplicationController def index @products = Product.all + @categories = Product.categories end def edit @@ -39,7 +40,7 @@ class ProductsController < ApplicationController private def product_params - params.require(:product).permit(:name, :price, :avatar) + params.require(:product).permit(:name, :price, :avatar, :category) end end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 443227f..96d4633 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -1,2 +1,9 @@ module OrdersHelper + include ActionView::Helpers::TextHelper + + def order_to_sentence(order) + order.order_products.map { + |op| pluralize(op.count, op.product.name) + }.to_sentence + end end diff --git a/app/models/product.rb b/app/models/product.rb index e7f09dc..5a7542f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,12 +11,15 @@ # avatar_content_type :string(255) # avatar_file_size :integer # avatar_updated_at :datetime +# category :integer default(0) # class Product < ActiveRecord::Base has_many :order_products has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium + enum category: %w(food beverages other) + validates :name, presence: true 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"] }, diff --git a/app/models/user.rb b/app/models/user.rb index 4468325..11f716e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,8 +16,13 @@ # last_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_ip :string(255) -# dagschotel :reference +# admin :boolean # 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 diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb index 4d42f29..916e9d9 100644 --- a/app/views/orders/new.html.erb +++ b/app/views/orders/new.html.erb @@ -1,4 +1,4 @@ -