problem with the "detail"-method

Sven Wildermann wrote:

class FormController < ApplicationController   def index     @form = Form.find(:first)     @form.update_attributes(params[:form])

    @detail = @form.detail     @detail.update_attributes(params[:detail])   end end

IIRC, given the code above as the main clue, you might need:

class form < ActiveRecord::Base   # a form model has a related detail model   has_one :detail end

class detail < ActiveRecord::Base   # and vice-versa   belongs_to :form end

The details table needs to have a column named form_id, spec'ed as integer, the forms table gets no additional field.

If there can be more than one detail model related to a form, then just the form model specification changes... it notes has_many, and the related model is pluralized.

class form < ActiveRecord::Base   # a form model has a related detail model   has_many :details end

Sven Wildermann wrote:

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occured while evaluating nil.update_attributes"

Can you show the POST from your log file... I'd like to see what your params hash looks like.

From earlier in the post-stream:

class FormController < ApplicationController   def index     @form = Form.find(:first)     @form.update_attributes(params[:form])

    @detail = @form.detail     @detail.update_attributes(params[:detail])   end end

From your log:

{"commit"=>"Speichern", "action"=>"index", "controller"=>"form", "form"=>{"kurztext"=>"This is a test for the talk"}, "detail"=>{"detailtext"=>"Test for the talk"}}

Something is truly bizarre with this example you are trying to follow... and I can't say that I fathom the intent of the example in the tutorial. So I went to look, and found a PDF about Rails at video2brain, but unfortunately, Ich spreche kein Deutsches.

Strange issues with this example:

You generally don't POST to the index method... that's usually a GET.

This code will always be modifying the first form due to the Form.find(:first) statement... perhaps there is only supposed to be one.

The detail model in params doesn't contain a form_id. You could remedy that by:

@form = Form.find(:first) @form.update_attributes(params[:form])

if @form.detail   @detail = @form.detail else   @detail = Detail.new end

@detail.form_id = @form.id @detail.update_attributes(params[:detail])

That should at least get you a value for form_id in the detail model (you did add form_id as integer to your details table, no?))

But this example is "wrong" in so many ways. Finish it if you must, then promptly forget this video2brain... gibberish.

Step up to Rails3, and find a couple of Rails 3 tutorials. You'll be much better served spending your time on those.

Ar Chron wrote:

From earlier in the post-stream:

class FormController < ApplicationController   def index     @form = Form.find(:first)     @form.update_attributes(params[:form])

    @detail = @form.detail     @detail.update_attributes(params[:detail])   end end

From your log:

{"commit"=>"Speichern", "action"=>"index", "controller"=>"form", "form"=>{"kurztext"=>"This is a test for the talk"}, "detail"=>{"detailtext"=>"Test for the talk"}}

Something is truly bizarre with this example you are trying to follow... and I can't say that I fathom the intent of the example in the tutorial. So I went to look, and found a PDF about Rails at video2brain, but unfortunately, Ich spreche kein Deutsches.

Hast du ein URL? I can read German (though I've never used Rails 3)...

Best,

Marnen Laibow-Koser wrote:

Hast du ein URL? I can read German (though I've never used Rails 3)...

Hi Marnen,

I was trying to get an idea of the lesson by browsing the "course contents" in this pdf:

www.video2brain.com/de/pdf-toc-60.pdf