storing and reading information from cookies is incredibly simple in Rails. much like storing information in the session, the syntax for using cookies is
cookies[:key_name] = “Vicky Visitor”
So if all you care about is the user, you can do something like this:
cookies[:user_id] = @user.id
and when you’re ready to retrieve the information:
@user = User.find(cookies[:user_id]) if cookies[:user_id]
once you have the user, you should be able to figure out what their last order was, their name, etc.
I just realized something: that’s assuming you want to use cookies (want to remember the person the next time they visit your site). If you want to only remember them while they’re visiting, you should be doing the same thing, except using the session instead.
I think the problem that you’re running into is that find(:all) returns an array of customers (in this case only one), not a single instance of a customer like you need. And if you’re doing a search by an id, you don’t need to use conditions