Problem with the "detail"-method

Hey,

i am very new with handling Ruby on Rails, so i did the Video-Tutorial
of “video2brain”.
They use an older Version of Rails (1.8… - i guess) and in an
controller-file they want me to do the following:

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

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

end
end

But now it says, that the method “detail” (in @details =
@form.detail) does not exist. I tried to get help with google - but
that wasnt succesful.

On Sep 22, 4:05 am, Sven W. [email protected] wrote:

@form.update_attributes(params[:form])

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

end
end

But now it says, that the method “detail” (in @details =
@form.detail) does not exist. I tried to get help with google - but
that wasnt succesful.

What does your Form model look like? Can you post the code for that?

@detail = @form.detail

should be

@detail = @form.details

you are missing an s

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

belond_to and has one in your models?

On 22 Sep., 14:58, Tim S. [email protected] wrote:

But now it says, that the method “detail” (in @details =
@form.detail) does not exist. I tried to get help with google - but
that wasnt succesful.

What does your Form model look like? Can you post the code for that?

My Form model is an very empty:

class Form < ActiveRecord::Base
end

  • I just did what they told me in the “video2brain”- Tutorial.
    So can you tell me how that Form Model has to look like?

On 22 Sep., 15:53, radhames brito [email protected] wrote:

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

belond_to and has one in your models?

No - i even did not change anything in my model files, because of
exactly acting like the “video2brain”-tutorial …

On 22 Sep., 15:52, radhames brito [email protected] wrote:

@detail = @form.detail

should be

@detail = @form.details

you are missing an s

I added the S - and so the fault report changed to: undefined method
`details’ for #Form:0x8917af0 (just the S in details is new in this
error message). Cant be the Solution

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

exactly acting like the “video2brain”-tutorial …

Is there a table called forms?
Is there a ‘detail’ field in the forms table?

Colin

There is a datebase called "formulare.
This database has a table called “forms” and a table called “details”

  • but there is no detail field in the “forms”-table.

So i need to create this field, correct?

On 23 September 2010 08:32, Sven W. [email protected]
wrote:

On 22 Sep., 15:53, radhames brito [email protected] wrote:

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

belond_to and has one in your models?

No - i even did not change anything in my model files, because of
exactly acting like the “video2brain”-tutorial …

Is there a table called forms?
Is there a ‘detail’ field in the forms table?

Colin

On 23 Sep., 10:25, Sven W. [email protected] wrote:

  • but there is no detail field in the “forms”-table.

So i need to create this field, correct?

Actually i created the “detail”-field in the forms-table and after
pressing F5 i got another fault message:

undefined method `update_attributes’ for “”:String

… sound like progress :wink:

On 23 September 2010 09:25, Sven W. [email protected]
wrote:

belond_to and has one in your models?
This database has a table called “forms” and a table called “details”

  • but there is no detail field in the “forms”-table.

So i need to create this field, correct?

No, I think it is more likely that you need to setup a relationship
between the tables so that form has_many details. This should all be
in the tutorial however.

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) and
http://railstutorial.org/ is good.

Colin

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 -
So could you (or someone else) tell me, why this error message appears
and what i need to do to go on?

  • Thank you very much for your help !

On 23 September 2010 09:42, Sven W. [email protected]
wrote:

On 23 September 2010 08:32, Sven W. [email protected] wrote:
Is there a ‘detail’ field in the forms table?
between the tables so that form has_many details. This should all be
Thanks for that advice. But i really want to finish this chapter of
the tutorial -
So could you (or someone else) tell me, why this error message appears
and what i need to do to go on?

As I said I think it is likely that you should have setup a
relationship between the models. You may have missed something in the
tutorial (or the tutorial is missing details).

Colin

On 23 September 2010 10:52, Sven W. [email protected]
wrote:

On 23 September 2010 09:25, Sven W. [email protected] wrote:

exactly acting like the “video2brain”-tutorial …
So i need to create this field, correct?

Colin

… The tutorial is missind details - F***!

Maybe you could explain to me how to setup a relationship between the
models? Otherwise i will google or do an other tutorial…
Thank you so far

That is what I suggested in the first place, to quote myself:

I would start by looking at the Rails Guides (google it) and http://railstutorial.org/ is good.
I would suggest that you use Rails 3 if you are not already doing so
as it is now the current version, though it is still very new, so
those who will try to help you are still learning themselves.
There is a Rails Guide specifically on ActiveRecord Relationships but
I would start with Getting Started.

Colin

On 23 Sep., 11:26, Colin L. [email protected] wrote:

On 23 September 2010 08:32, Sven W. [email protected] wrote:
Is there a ‘detail’ field in the forms table?
between the tables so that form has_many details. This should all be
Thanks for that advice. But i really want to finish this chapter of
the tutorial -
So could you (or someone else) tell me, why this error message appears
and what i need to do to go on?

As I said I think it is likely that you should have setup a
relationship between the models. You may have missed something in the
tutorial (or the tutorial is missing details).

Colin

… The tutorial is missind details - F***!

Maybe you could explain to me how to setup a relationship between the
models? Otherwise i will google or do an other tutorial…
Thank you so far

On 23 Sep., 12:02, Colin L. [email protected] wrote:

On 23 September 2010 09:25, Sven W. [email protected] wrote:

exactly acting like the “video2brain”-tutorial …
So i need to create this field, correct?

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

I would suggest that you use Rails 3 if you are not already doing so
as it is now the current version, though it is still very new, so
those who will try to help you are still learning themselves.
There is a Rails Guide specifically on ActiveRecord Relationships but
I would start with Getting Started.

Colin

I dont use Rail 3, but 1.8.6 - because the Autor of the Tutorial used
that Version, too.
Would you recommend to use the 2. or the 3. Version?

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

On 23 September 2010 14:48, Sven W. [email protected]
wrote:

I dont use Rail 3, but 1.8.6 - because the Autor of the Tutorial used
that Version, too.
Would you recommend to use the 2. or the 3. Version?

I think I answered that already.

Colin

Colin L. wrote:

On 23 September 2010 14:48, Sven W. [email protected]
wrote:

I dont use Rail 3, but 1.8.6 - because the Autor of the Tutorial used
that Version, too.

Oh, hold on a minute. Rails 1.8.6 doesn’t exist; that looks like a Ruby
version number. So…what version of Rails does the tutorial actually
use?

Would you recommend to use the 2. or the 3. Version?

I think I answered that already.

Colin

Best,

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

On 23 Sep., 16:25, Ar Chron [email protected] wrote:

end
has_many :details
end


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

Thanks! That was almost successful …I used the “has_one” -command and
deleted the following line in form_controller.rb:

@detail.update_attributes(params[:detail])”.
Actually i can see two boxes - the second one is the “detail”-box.
the first one saves my changes. the detail-box does not.

Pasting the “@detail.update_attributes(params[:detail])” -line into
the form_controller.rb , the following error message appears:

" NoMethodError in FormController#index

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"

Whats wrong? And Thank you very very very (!) much for your help -
thats awesome to get help by friendly people :]