Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huanvl
venshop
Commits
1df0b000
Commit
1df0b000
authored
Oct 25, 2013
by
vulehuan
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new product featured
parent
61d967f4
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
2 deletions
+24
-2
venshop_app/app/controllers/products_controller.rb
+13
-1
venshop_app/app/models/product.rb
+3
-0
venshop_app/app/models/product_category.rb
+2
-0
venshop_app/app/views/products/_fields.html.erb
+2
-0
venshop_app/db/migrate/20131023094033_create_products.rb
+1
-0
venshop_app/db/schema.rb
+1
-0
venshop_app/lib/tasks/sample_data.rake
+2
-1
No files found.
venshop_app/app/controllers/products_controller.rb
View file @
1df0b000
...
@@ -21,13 +21,25 @@ class ProductsController < ApplicationController
...
@@ -21,13 +21,25 @@ class ProductsController < ApplicationController
@product
=
Product
.
new
@product
=
Product
.
new
end
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
def
user_items
end
end
private
private
def
product_params
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
end
# Before filters
# Before filters
...
...
venshop_app/app/models/product.rb
View file @
1df0b000
class
Product
<
ActiveRecord
::
Base
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)
# Returns recommended products (order by rate, and available)
def
self
.
get_recommended_products
(
options
=
{
limit:
8
})
def
self
.
get_recommended_products
(
options
=
{
limit:
8
})
limit
=
options
[
:limit
]
limit
=
options
[
:limit
]
...
...
venshop_app/app/models/product_category.rb
View file @
1df0b000
class
ProductCategory
<
ActiveRecord
::
Base
class
ProductCategory
<
ActiveRecord
::
Base
has_many
:product
Vinh Nguyen
@vinhnx
commented
Nov 04, 2013
Reporter
should be plural form.
has_many
:products
should be plural form. ```ruby has_many :products ```
Please
register
or
sign in
to reply
end
end
\ No newline at end of file
venshop_app/app/views/products/_fields.html.erb
View file @
1df0b000
<%=
render
'shared/error_messages'
,
entity:
@product
%>
<%=
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
.
label
:name
%>
<%=
f
.
text_field
:name
,
class:
"form-control"
%>
<%=
f
.
text_field
:name
,
class:
"form-control"
%>
...
...
venshop_app/db/migrate/20131023094033_create_products.rb
View file @
1df0b000
...
@@ -15,6 +15,7 @@ class CreateProducts < ActiveRecord::Migration
...
@@ -15,6 +15,7 @@ class CreateProducts < ActiveRecord::Migration
t
.
decimal
:price
t
.
decimal
:price
t
.
integer
:product_category_id
t
.
integer
:product_category_id
t
.
integer
:user_id
t
.
integer
:user_id
t
.
boolean
:status
t
.
timestamps
t
.
timestamps
end
end
...
...
venshop_app/db/schema.rb
View file @
1df0b000
...
@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 20131024162951) do
...
@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 20131024162951) do
t
.
decimal
"price"
,
precision:
10
,
scale:
0
t
.
decimal
"price"
,
precision:
10
,
scale:
0
t
.
integer
"product_category_id"
t
.
integer
"product_category_id"
t
.
integer
"user_id"
t
.
integer
"user_id"
t
.
boolean
"status"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
end
end
...
...
venshop_app/lib/tasks/sample_data.rake
View file @
1df0b000
...
@@ -92,7 +92,8 @@ namespace :db do
...
@@ -92,7 +92,8 @@ namespace :db do
review_count:
review_count
,
review_count:
review_count
,
price_currency:
price_currency
,
price_currency:
price_currency
,
price:
price
,
price:
price
,
product_category_id:
category_id
product_category_id:
category_id
,
status:
1
)
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment