Problem with the "detail"-method

Sven W. wrote:

On 23 Sep., 10:36, Colin L. [email protected] wrote:

ooooh wait , is a one to one relation chip, do you have

I think you might be much better finding a tutorial for the version of
rails you are using however. �If it is out of date you will forever be
coming up against problems.

I would start by looking at the Rails Guides (google it) andhttp://railstutorial.org/is good.

Colin

Thanks for that advice. But i really want to finish this chapter of
the tutorial -

Don’t bother. If it’s out of date, just drop it and find a current
tutorial.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 23 Sep., 20:28, Ar Chron [email protected] wrote:

Sven W. 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.

Posted viahttp://www.ruby-forum.com/.

Hey (especially to Ar Chron),

i just get an POST in my log file, if there is no fault message in the
beginning (i guess that makes sense).
Therefore i deleted the “”@detail.update_attributes(params[:detail])"
line in form_controller.rb, wrote a short text in both boxes and
pressed “Speichern” (> the German word for “Submit”).
At least i got the following post in my log file:

Processing FormController#index (for 127.0.0.1 at 2010-09-24 09:11:59)
[POST]
Session ID: 7d9c4ddeaff0f55ddf9356003f9a1750
Parameters: {“commit”=>“Speichern”, “action”=>“index”,
“controller”=>“form”, “form”=>{“kurztext”=>“This is a test for the
talk”}, “detail”=>{“detailtext”=>“Test for the talk”}}
[4;35;1mForm Load (0.000000) [0m [0mSELECT * FROM forms LIMIT
1 [0m
[4;36;1mForm Columns (0.000000) [0m [0;1mSHOW FIELDS FROM
forms [0m
[4;35;1mSQL (0.000000) [0m [0mBEGIN [0m
[4;36;1mForm Update (0.031000) [0m [0;1mUPDATE forms SET
checkbox = 0, detail = ‘’, auswahlbuttons = ‘Nein’, kurztext =
‘This is a test for the talk’, datum = ‘2008-06-01’, detailtext =
‘’, auswahl = ‘RoR’, langtext = ‘Mein Langtext…’ WHERE id =
1 [0m
[4;35;1mSQL (0.016000) [0m [0mCOMMIT [0m
[4;36;1mDetail Load (0.000000) [0m [0;1mSELECT * FROM details
WHERE (details.form_id = 1) LIMIT 1 [0m
Rendering form/index
Completed in 0.06300 (15 reqs/sec) | Rendering: 0.01600 (25%) | DB:
0.04700 (74%) | 200 OK [http://localhost/form]

Thanks for your help (in hope of advance)

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.

Sven W. 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.

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
http://www.marnen.org
[email protected]

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:

On 24 Sep., 19:29, Ar Chron [email protected] wrote:

end
PDF about Rails at video2brain, but unfortunately, Ich spreche

end

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

Posted viahttp://www.ruby-forum.com/.

Thank you very much, everybody - it works!

@ marnen Laibow-Koser: einen URL wofür? Das Video2Brain-Tutorial ist
nur käuflich erhältlich.

regards,

Sven