ラインアイテムのインデックスページで、行をリストするコードを書きましたが、リストされず、エラーもありません
<% @line_items.each do |line_item| %>
<tr>
<td><%= line_item.phone_id %></td>
<td><%= line_item.cart_id %></td>
<td><%= link_to 'Show', line_item %></td>
<td><%= link_to 'Edit', edit_line_item_path(line_item) %></td>
<td><%= link_to 'Destroy', line_item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
(リストされているはずですが、エラーがないことに注意してください)これがインデックスページの私のコードです
エラー 2
実際、私の目的はカートに追加することで、カートに追加するリンクを提供します。ストアインデックスではカートに追加するはずですが、カートに追加をクリックすると白い画面になり、本の中で(レールで開発するアジャイル)ボタン(代わりにリンクを使用しました)ただし、ボタンを使用すると、保護された属性を一括割り当てできません:電話は私のコントローラーです
def create
@cart = current_cart
phone = Phone.find(params[:phone_id])
@line_item = @cart.line_items.build(:phone => phone)
respond_to do |format|
if @line_item.save
format.html { redirect_to(@line_item.cart,:notice => 'Line item was successfully created.' ) }
format.xml { render :xml => @line_item,:status => :created, :location => @line_item }
else
format.html { render action: "new" }
format.json { render json: @line_item.errors, status: :unprocessable_entity }
end
end
end
また、ここに私の店のインデックスがあります
<br />
<div id="content" class="float_r">
<h1>New Products</h1>
<% @phones.each do |phone| %>
<div class="product_box">
<a href="productdetail.html"><%=image_tag( phone.image_url,class:'list_image') %></a>
<h3><%= phone.model %></h3>
<p class="product_price"><span class="product_price" ><%= number_to_currency(phone.price) %></span></p>
<p class="add_to_card"><%= button_to 'Add to Cart' , line_items_path(:phone_id => phone) %></p>
<p class="detail"><%= link_to 'details' , phone_path(phone) %></p>
</div>
<% end %>
それがリンクの場合、ボタンのときに白いページだけが表示されますこのエラー:保護された属性を一括割り当てできません:電話