Forum: Ruby on Rails Cookies are not saved

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Adam M. (Guest)
on 2008-11-17 22:54

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])

    respond_to do |format|
        @product =
        @product.image_id =
        @product.order_id =
        cookies[:product_id] =
        flash[:notice] = 'Image was successfully created.'
        format.html {redirect_to('/karte/waehlen')}
        format.xml  { render :xml => @image, :status => :created,
:location => @image }
        format.html { render :action => "new" }
        format.xml  { render :xml => @image.errors, :status =>
:unprocessable_entity }

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)

I try to get the product_id from the cookie.

The waehlen.html.erb looks like

<div id="formatCenterContainer">
  <%= 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):

10: </div>
11: <div id="formatCenterContainer">
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
This topic is locked and can not be replied to.