Moin Adam,

also ich speichere folgendermaßen meine Cookies:

cookies[:visitor_id] = { :value => "#{visitor.id}",
        :expires => 2.days.from_now
      }

Evtl. liegt da bei der Fehler, das deine erste Speicherung
eher die Variante ist, wie man normalerweise Daten aus
dem Cookie ausliest.


Viele Grüße,

Daniel



Am 18.11.2008 um 09:09 schrieb Adam Meyer:

Hi,

ich entwickel gerade eine eine RubyOnRails Webseite mit Ruby 1.8 und
Rails 2.0.2.

Ich erstelle an der einen Stelle ein Product object und speicher es in
ein Cookie

Code:

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

     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')}

Dann redirecte ich zum karte controller und waehlen action

Der karte controller sieht dann so aus.

Code:

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

dort lese ich dir product id wieder aus.

Die waehlen.html.erb möchte das dann ausgeben

Code:

<div id="formatCenterContainer">
 <%= image_tag(@image.filename, :size => "190x153") %>
</div>

Leider bekomme ich eine

Code:

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: </div>
11: <div id="formatCenterContainer">
12:   <%= image_tag(@image.filename, :size => "190x153") %>

Ich entwickel auf Windows, habe mal im Cookie Ordner geschaut, da wird
garkein Cookie angelegt. Daher auch das nil object.

Warum legt er das Cookie nicht an? Muss ich da noch extra weiß
einstellen? Kann das deaktiviert sein?

Auch wenn es nur was triviales ist, bin ich über jede Hilfe dankbar,
komme nicht weiter an dieser Stelle.

Gruß

Adam
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug

_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug

Antwort per Email an