# Cookies are not saved

**URL:** <https://www.ruby-forum.com/t/cookies-are-not-saved/153484>\
**Category:** Rails\
**Created:** [November 17, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/cookies-are-not-saved/153484 "2008-11-17T21:54:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adammontgomery](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@adammontgomery](https://www.ruby-forum.com/u/adammontgomery)\
**Post date:** [November 17, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/cookies-are-not-saved/153484/1 "2008-11-17T21:54:27Z")

</div>

Hi,

I’m developing my first RoR application and working first time with  
cookies on RoR.

I create a product object, save it and set the id into the cookie

def create  
@image = Image.new(params[:image])

```
respond_to do |format|
  if @image.save
    @product = Product.new
    @product.image_id = @image.id
    @product.order_id = @order.id
    @product.save
    cookies[:product_id] = @product.id.to_s
    flash[:notice] = 'Image was successfully created.'
    format.html {redirect_to('/karte/waehlen')}
    format.xml { render :xml => @image, :status => :created,

```

:location =\> @image }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @image.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

Then I redirect to the “karte” controller and “waehlen” action

The karte controller looks like this

class KarteController \< ApplicationController  
def waehlen  
@product = Product.find(cookies[:product\_id])  
@image = Image.find(@product.image\_id)  
end  
end

I try to get the product\_id from the cookie.

The waehlen.html.erb looks like

 \<%= image\_tag(@image.filename, :size =\> "190x153") %\>

I get a NoMethodError

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.filename

Extracted source (around line #12):

9:  
10:   
11:

  
12: \<%= image\_tag(@image.filename, :size =\> “190x153”) %\>

I checked the Cookie folder on my filesystem. There is no Cookie.

Do I have activate cookies? I already browsed for the problem, but I  
find only information about read/write cookies and other options.

Cheers Adam
