Commit 1df0b000 by vulehuan

add new product featured

parent 61d967f4
......@@ -21,13 +21,25 @@ class ProductsController < ApplicationController
@product = Product.new
end
def create
@product = Product.new(product_params)
user = current_user
@product.user_id = user.id
if @product.save
flash[:success] = "Add new product successfully!"
redirect_to @product
else
render 'new'
end
end
def user_items
end
private
def product_params
params.require(:product).permit(:name, :description, :headline, :availability, :code, :condition, :image_small, :image_medium, :price_currency, :price)
params.require(:product).permit(:name, :description, :headline, :availability, :code, :condition, :image_small, :image_medium, :price_currency, :price, :product_category_id)
end
# Before filters
......
class Product < ActiveRecord::Base
validates :name, :availability, :code, :condition, :image_medium, :price, :price_currency, presence: true
belongs_to :product_category
# Returns recommended products (order by rate, and available)
def self.get_recommended_products(options = { limit: 8 })
limit = options[:limit]
......
class ProductCategory < ActiveRecord::Base
has_many :product
Please register or sign in to reply
end
\ No newline at end of file
<%= render 'shared/error_messages', entity: @product %>
<%= f.label :product_category_id %>
<%= collection_select(:product, :product_category_id, ProductCategory.all, :id, :name, {}, class: 'form-control') %>
<%= f.label :name %>
<%= f.text_field :name, class: "form-control" %>
......
......@@ -15,6 +15,7 @@ class CreateProducts < ActiveRecord::Migration
t.decimal :price
t.integer :product_category_id
t.integer :user_id
t.boolean :status
t.timestamps
end
......
......@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 20131024162951) do
t.decimal "price", precision: 10, scale: 0
t.integer "product_category_id"
t.integer "user_id"
t.boolean "status"
t.datetime "created_at"
t.datetime "updated_at"
end
......
......@@ -92,7 +92,8 @@ namespace :db do
review_count: review_count,
price_currency: price_currency,
price: price,
product_category_id: category_id
product_category_id: category_id,
status: 1
)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment