THanks for the response. That helps clear a few things up. As fasr as
the Model.parent.date reference, that was my bad as I wasn't sure
where I had to start the traversing of the tables. It makes sense now
that I realize I'm in the class and at the top of this chain.
zycte <zycte@mailinator.com> wrote:
>On 2006-06-21 04:23:40 +0200, Tim <tklemmer@lanline.com> said:
>>
>>
>> Here are my issues:
>>
>> 1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
>> responds with "Can't load file". The only way to get the require
>> command to work is to issue it with the full path name to the .rb file
>> as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
>> missing something in my configuration (a path or series of paths) so
>> that I don't have to search for the file and issue the full path name?
>
>In irb, ask the value of $LOAD_PATH. It contains the directories from
>which you can load relatively.
>
>> 2) I'm totally lost at this point when to use @variables versus
>> :variables or :symbols.
>
>@variable is an instance variable. If you assign to an @variable in any
>method of a class, the variable stays in the class instance. :symbols
>are symbols, that is, they are strings that are interned by Ruby, so
>two symbols with the same name point to the same address and can be
>compared very quickly. Rails uses a lot of :symbols, which can make it
>a bit confusing at first. You should know that when you have to use a
>:symbol, it is as a parameter of a method that will usually do some
>metaprogramming. Look in the rails reference for the details of each
>function.
>
>> 3) I have a model which has a belongs_to clause. Later on in the model
>> I have a method which says:
>> def inception
>> Model.parent.inception_date
>> end
>> If I open a Rails Console and say:
>> x = Model.find(12000)
>> puts x.inception
>> I get an error saying undefined method -- parent. BUT I can say in IRB
>> x = Model.parent.inception_date
>> Why is that?
>
>I don't understand why you call the parent method on the Model class
>and not on the instance. You could do:
>
>class Model
> belongs_to :other
>
> def inception
> other.inception_date
> end
>
>end
>
>class Other
> # Rais adds an inception_date accessor here cause it is defined in
>your database
>end