Answer the question
In order to leave comments, you need to log in
Ruby on Rails: render - display menu, cart on every page of the site?
Good evening! Interested in the following question, how to add a shopping cart for an online store to each page of the site (basket as in the Agile Web Dev book), I have 4 models - Category, Product, Cart, Post.
layout application.html.erb
<%= render :partial => 'categories/cart', :locals => {:cart => @cart}%>
<% if @cart.blank? %><br/>
<% else %><br/>
<% for item in @cart.items %><br/>
<%= item.quantity %> × <%=h item.title %><%= number_to_currency(item.price) %><br/>
<% end %><br/>
Итого: <%= number_to_currency(@cart.total_price) %><br/>
<%= button_to 'Очистить корзину', :controller => 'categories', :action => 'empty_cart'%><br/>
<% end %>
<%= render :partial => 'posts/post', :collections => Post.all %>
Answer the question
In order to leave comments, you need to log in
If you cannot get the cart from the session, then take a closer look in the book where you took the cart from, find_cart method:
def find_cart
session[:cart] ||= Cart.new
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question