제품, 수하물 및 기타 사항이있는 전자 상거래 웹 사이트가 있습니다.레일 : 제품이 없음으로 설정되었습니다.
@produit과 @produits 변수는 모두 nil로 설정되지만 이유는 알 수 없습니다. 여기
는 produit.rb
이다 : 나는 또한/인덱스 PRODUITS에서이보기가
class ProduitsController < ApplicationController
def index
@produits = Produit.all
@order_item = current_order.order_items.new(produit_params)
if @order_item.save
format.html { redirect_to @order_item, notice: 'Le produit a été ajouté au panier !' }
format.json { render json: @order_item, status: :created, location: @order_item }
format.js
else
format.html { render action: 'create', notice: 'Le produit n\'a pas été ajouté au panier' }
format.json { render @order_item.errors, status: unprocessable_entity }
format.js
end
end
def show
@produit = Produit.find(params[:id])
end
private
def produit_params
params.require(:produit).permit(:nom, :quantite, :description, :denomination, :artisan, :categorie, :prix, :photo)
end
end
: 여기
class Produit < ActiveRecord::Base
has_many :order_items
default_scope { where(active: true) }
mount_uploader :photo, PhotoUploader
validates :nom, presence: true
validates :artisan, presence: true
validates :quantite, presence: true
validates :categorie, presence: true
validates :denomination, presence: true
validates :description, presence: true
validates :prix, presence: true
validates :photo, presence: true
end
컨트롤러 여기
<%= render partial: 'layouts/navbarindex' %>
<%= render partial: 'produits/header' %>
<div id="path-progress-bar">
<p>Accueil</p>
<p>/</p>
<p style="color:black">Boutique de produits breton</p>
</div>
<section id="marche-breton-container">
<%= render template: 'categories/index' %>
<div id="produits-column-container">
<% if @produits %>
<% @produits.in_groups_of(4, false).each do |g| %>
<% g.each do |produit| %>
<%= render partial: "produits/produit_row", produit: @produit, order_item: @order_item %>
<% end %>
<% end %>
<% end %>
</div>
</section>
및 렌더링 _produit_row.html.erb
입니다 :
<div id="produits-row-container">
<div id="fiche-produit-container">
<%= form_for order_item, remote: true do |f| %>
<div id="produit-img">
<%= link_to produits_show_path do %>
<%= image_tag produit.photo %>
<% end %>
</div>
<div id="produit-nom">
<%= produit.nom %>
</div>
<div id="produit-prix">
<%= number_to_currency(produit.prix, unit: '€', format: "%n%u") %>
</div>
<div id="produit-au-panier">
<%= image_tag('icon/icon-panier') %>
<%= f.submit 'Ajouter au panier' %>
</div>
<% end %>
</div>
</div>
문제는보기에 아무 것도 표시하지 않도록 @produit
및 @produits
가 나는 제품이 설정되어 active_admin 세션에도 불구하고, 전무로 설정되어 있다는 점이다.
UPDATE는 다음 logs
:
Started GET "/mon-marche-breton" for ::1 at 2017-05-24 09:17:47 +0200
Processing by MarcheBretonController#index as HTML
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
Rendered layouts/_cart_text.html.erb (6.9ms)
Rendered layouts/_navbarindex.html.erb (26.4ms)
Rendered produits/_header.html.erb (3.4ms)
Categorie Load (0.3ms) SELECT `categories`.* FROM `categories`
Rendered categories/index.html.erb (5.5ms)
Rendered produits/index.html.erb (39.2ms)
Rendered marche_breton/index.html.erb within layouts/application (40.3ms)
Rendered layouts/_footer.html.erb (3.2ms)
Completed 200 OK in 253ms (Views: 242.1ms | ActiveRecord: 3.6ms)
Started GET "/assets/bg/bg-banner.png" for ::1 at 2017-05-24 09:17:48 +0200
Started GET "/assets/bg/footer.png" for ::1 at 2017-05-24 09:17:48 +0200
Started GET "/assets/bg/before-footer.png" for ::1 at 2017-05-24 09:17:48 +0200
레일 콘솔에서 'Produit.all'이 데이터를 가져 오는 지 확인 했습니까? 또한, 저장 한 제품에는 'active : true' 속성이 있습니까? 'default_scope {where (active : true)}'를 기억하십시오. –
'Produits # index'는'OrderItem'에 대한 매개 변수를 받아서는 안됩니다. GET 요청이어야합니다. '@ order_item.save' 조건을'OrderItems' 컨트롤러로 이동하는 것을 고려하십시오 (아마도'create' 액션에서). – coreyward
@AlejandroMontilla 예 레일 콘솔을 확인했는데'Produit.all'이 active_admin 세션에 입력 한 데이터를 가져 왔습니다. 이것이 내가 이해하지 못하는 이유입니다 ... – justinedps26