Undefined method "xxx" of a model when calling a helper

Hi --

Hi all

I'm creating a shop page. I have a cart model that looks like the following:

class Cart attr_reader :line_items

def get_line_item id    @line_items.each do |l|      return l if l.id == id    end end

    def get_line_item(id)       @line_items.find {|l| l.id == id }     end

def initialize    @line_items = end

def empty!    initialize end

def empty?    return true if @line_items.empty?    false end

    def empty?       @line_items.empty?     end

end

And I have some helper methods in application_helper.rb:

module ApplicationHelper def find_cart    session[:cart] ||= Cart.new

It seems a little odd to me to be manipulating the session data in a view (or view helper). You might want to find a way to juggle things so that this is back in the controller.

end

def empty_cart    find_cart.empty! end

def cart_empty?    return true if find_cart.empty? end

    def cart_empty?       find_cart.empty?     end

end

Then I want to display a partial form within the layout application.rhtml but only if the cart is not empty:

<%= render(:partial => 'warenkorb/warenkorb', :locals => {:cart => find_cart}) unless cart_empty? %>

But this displays me the following error:

undefined method `empty?' for #<Cart:0x230020c @line_items=>

Where does this error come from? I just don't get it, the Cart object is instantiated when calling find_cart, and the Cart class definitely does have a method called "empty?"!

I'm afraid I can't duplicate your error. I've tried to make up for it with a few code hints :slight_smile: (see above) Could the problem have something to do with caching and then changing the model file?

David