small medium large xlarge

Generic-user-small
25 Feb 2012, 15:56
LED (3 posts)

i followed the book helper method section

<%= hidden_div_if(@cart.line_items.empty?, :id => "cart") do %>
<%= render @cart %>
<% end %>

and insert it here in my application.html.erb file in layout folder

<!DOCTYPE html>
<html>
<head>
  <title>Pragprog Books Online Store</title>
  <%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %> 
  <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" %>
  <%= csrf_meta_tags %>
</head>
<body id="store">
	<div id="banner">
		<%= image_tag("logo.png")%>	
		<%=@page_title || "Pragmatic BookShelf"%>
	</div>	
		<div id="columns">
			<div id="side" >
		==>		<%= hidden_div_if(@cart.line_items.empty?, :id => "cart") do %>
		==>			<%= render @cart %>
		==>		<% end %>

				<%= link_to "Home", store_path %>
				<%= link_to "Contact", store_path %>
				<%= link_to "Questions", store_path %>
				<%= link_to "News", store_path %>
					<div id="time">
					<% @time = Time.now%>
					<%= @time.to_s(:short) %>	
					<br />
					You've been here <%= pluralize(@count.to_i, "time") %>
					</div>
			</div>
				<div id="main">	
					<%= yield %>
				</div>
		</div>	
</body>
</html>

but when i try to access my other routes such as localhost/carts

error occur saying

NoMethodError in Carts#index

Showing /home/led/Aptana Studio 3 Workspace/depot/app/views/layouts/application.html.erb where line #17 raised:

undefined method `line_items' for nil:NilClass
Extracted source (around line #17):

14: 	</div>	
15: 		<div id="columns">
16: 			<div id="side" >
17: 				<%= hidden_div_if(@cart.line_items.empty?, :id => "cart") do %>
18: <%= render @cart %>
19: <% end %>
20: 

i kinda figure it out when routing in other routs the @cart.line_items is the big deal i dont know if im right but i suspect is the error is this

hi i found this but it didint answer my question to http://forums.pragprog.com/posts/search?utf8=%E2%9C%93&q=hidden+cart

can anyone explain me why? im new in ROR thank you every one more power

You must be logged in to comment