在我的订单项索引页面中,我编写了列出行的代码,但它没有列出,也没有错误
<% @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
实际上,我的目的是添加到购物车,我提供了一个添加到购物车的链接,在商店索引中它应该添加到购物车,但是当我单击添加到购物车时,我得到的只是白屏,并且在书中(我们使用 Rails 开发敏捷)它是按钮(但我使用了链接)但是当我使用按钮时,我得到了这个 Can't mass-assign protected attributes: phone here is my controller
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 %>
如果是链接,当它是按钮时我只得到白页此错误:无法批量分配受保护的属性:电话