Commit 193525ad by Dao Minh Nhut

fix code convention

parent 2cbd592f
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@products = Product.all @products = Product.all
end end
end end
...@@ -3,34 +3,33 @@ class ProductsController < ApplicationController ...@@ -3,34 +3,33 @@ class ProductsController < ApplicationController
#before_filter :correct_user, only: :destroy #before_filter :correct_user, only: :destroy
#def show #def show
#@item = Product.find(params[:id]) #@item = Product.find(params[:id])
#end #end
def index def index
@item = Product.find(:all) @item = Product.find(:all)
#@items = Product.all.select do |i| #@items = Product.all.select do |i|
# i.category==params[:id] #i.category==params[:id]
#end #end
end end
def new def new
@item= Product.new @item= Product.new
render layout: "another_layout" render layout: "another_layout"
end end
def create def create
@item = current_user.items.new(params[:item]) @item = current_user.items.new(params[:item])
if @item.save if @item.save
flash[:success] = "Your item has successfully posted!" flash[:success] = "Your item has successfully posted!"
redirect_to current_user, layout: "another_layout" redirect_to current_user, layout: "another_layout"
else else
render 'new', layout: "another_layout" render 'new', layout: "another_layout"
end end
end end
def destroy def destroy
@item.destroy @item.destroy
redirect_to current_user redirect_to current_user
end end
private
def correct_user def correct_user
@item = current_user.items.find_by_id(params[:id]) @item = current_user.items.find_by_id(params[:id])
redirect_to root_url if @item.nil? redirect_to root_url if @item.nil?
......
<div class="span9 categories"> <div class="span9 categories">
<% @items_of_category.each do |i| %> <% @items_of_category.each do |i| %>
<div class="span5 center"> <div class="span5 center">
<h4><%= i.name%></h4> <h4><%= i.name%></h4>
......
<div class="span3"> <div class="span3">
<div class="sidebar-nav-fixed"> <div class="sidebar-nav-fixed">
<div class="well"> <div class="well">
<ul class="nav nav-list"> <ul class="nav nav-list">
<li class="nav-header">Category</li>
<li class="nav-header">Category</li> <!--% category_list.each do |cat| %-->
<!--% category_list.each do |cat| %--> <li><a href='/categories/<%= cat.id%>'><%=cat.name%></a></li>
<li><a href='/categories/<%= cat.id%>'><%=cat.name%></a></li> <!--%end%-->
<%end%> </ul>
</ul>
</div><!--/.well --> </div><!--/.well -->
</div> <!--/sidebar-nav-fixed --> </div> <!--/sidebar-nav-fixed -->
</div><!--/span--> </div><!--/span-->
\ No newline at end of file
<div class="span8 center"> <div class="span8 center">
<h3>Name: </h3><%= @product.name%><br><br>
<h3>Name: </h3><%= @item.name%><br><br>
</div><!--/span--> </div><!--/span-->
\ No newline at end of file
...@@ -15,7 +15,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do ...@@ -15,7 +15,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do
create_table "categories", force: :cascade do |t| create_table "categories", force: :cascade do |t|
t.string "name", limit: 255 t.string "name", limit: 255
t.string "description", limit: 255 t.string "description", limit: 65535
t.string "image", limit: 255 t.string "image", limit: 255
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
...@@ -25,7 +25,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do ...@@ -25,7 +25,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do
t.string "name", limit: 255 t.string "name", limit: 255
t.string "image", limit: 255 t.string "image", limit: 255
t.integer "price", limit: 4 t.integer "price", limit: 4
t.string "description", limit: 255 t.string "description", limit: 65535
t.integer "category_id", limit: 4 t.integer "category_id", limit: 4
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
......
...@@ -33,15 +33,15 @@ class ImportAmazon ...@@ -33,15 +33,15 @@ class ImportAmazon
end end
def get_response(page) def get_response(page)
response = @request.item_search( response = @request.item_search(
query: { query: {
'Keywords' => '*', 'Keywords' => '*',
'SearchIndex' => 'Blended', 'SearchIndex' => 'Blended',
'ResponseGroup' => 'Medium', 'ResponseGroup' => 'Medium',
'ItemPage' => page, 'ItemPage' => page,
} }
) )
response.to_h["ItemSearchResponse"].to_h["Items"].to_h["Item"] response.to_h["ItemSearchResponse"].to_h["Items"].to_h["Item"]
end end
end end
\ No newline at end of file
namespace :products do namespace :products do
desc 'Get products' desc 'Get products'
task import: :environment do task import: :environment do
ImportAmazon.new.import_product ImportAmazon.new.import_product
end end
end end
...@@ -6,4 +6,4 @@ class HomeControllerTest < ActionController::TestCase ...@@ -6,4 +6,4 @@ class HomeControllerTest < ActionController::TestCase
assert_response :success assert_response :success
end end
end end
\ No newline at end of file
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