Good evening! Interested in the following question how to add a shopping cart for an online store on each page of the website (shopping cart like in the book Agile Web Dev), I have 4 models — Category, Product, Cart, Post.
layout
application.html.erb<%= render :partial => 'categories/cart', :locals => {:cart => @cart}%>
partial
_cart.html.erb<% if @cart.blank? %>
<% else %>
<% for item in @cart.items %>
<%= item.quantity %> × <%=h item.title %><%= number_to_currency(item.price) %>
<% end %>
Total: <%= number_to_currency(@cart.total_price) %>
<%= button_to 'empty basket', :controller => 'categories', :action => 'empty_cart'%>
<% end %>
In this scenario the shopping cart is displayed only in the view controller Categories. Can't figure out how to get from the session session[:cart] or else somehow the necessary data.
And another question, how to display a menu on each page now like this:
<%= render :partial => 'posts/post', :collections => Post.all %>
Thanks for the replies.