diff --git a/app/controllers/shop/products_controller.rb b/app/controllers/shop/products_controller.rb index 3e6ca299..13920a9e 100644 --- a/app/controllers/shop/products_controller.rb +++ b/app/controllers/shop/products_controller.rb @@ -14,7 +14,9 @@ def show render text: html } format.js { - render json: product.shop_as_json + product = shop.products.where(handle: params[:handle]).first + json = product ? product.shop_as_json : {} + render json: json } end end diff --git a/spec/controllers/shop/products_controller_spec.rb b/spec/controllers/shop/products_controller_spec.rb index 80f32bee..139c002b 100644 --- a/spec/controllers/shop/products_controller_spec.rb +++ b/spec/controllers/shop/products_controller_spec.rb @@ -68,6 +68,15 @@ response.status.should eql 404 end + context 'js' do # 通过js访问时,返回空json,否则会导致[最近浏览列表]无法显示 + + it "should be success" do + get 'show', handle: 'no-exists-handle', format: :js + response.status.should eql 200 + end + + end + end end