# Problem With Active Record. Associations Showing Error ..ple

**URL:** <https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120>\
**Category:** Rails\
**Created:** [September 17, 2010, 9:45am UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120 "2010-09-17T09:45:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 9:45am UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/1 "2010-09-17T09:45:48Z")

</div>

i am stuck somewhere with The Acrive record association .  
whenever i try to get the value from another table it gives me the  
foolowing error  
“undefined method `journal\_name’ for nil:NilClass”

MY Controller

def index  
@ledgers = Ledger.find(:all)  
@finaccounts = Finaccount.find(:all)  
@journels = Journel.all  
respond\_to do |format|  
format.html  
format.pdf { render :layout =\> false }  
end

view:

```
<td><%=h ledger.journel.journal_name %></td>

```

Models :

1. Journel

class Journel \< ActiveRecord::Base  
has\_many :ledgers  
end

1. 

class Ledger \< ActiveRecord::Base  
belongs\_to :journel  
end

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 11:07am UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/2 "2010-09-17T11:07:21Z")

</div>

Apparently one or more of your ledgers doesn’t have a journel?

Try:

\<%=h ledger.journel.journal\_name if ledger.journel %\> to see the ones that don't have journels.

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 11:41am UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/3 "2010-09-17T11:41:54Z")

</div>

Thanks For the Help Heinz S…  
But i need To Know Is there anything with rails 2.3.5 because to check  
wheather i have made any mistake in my application i created a sample  
application , and again it was the same error i got .  
waiting for your reply  
and one more thing …i am only a couple of months old to Ruby On rails  
.so please if possible suggest me how to make the associations between  
tables in rails.

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 11:55am UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/4 "2010-09-17T11:55:51Z")

</div>

If you are much interested in Rails Associations means, refer these  
URLs.

> **[Active Record Associations — Ruby on Rails Guides](https://guides.rubyonrails.org/association_basics.html)**
>
> Active Record AssociationsThis guide covers the association features of Active Record.After reading this guide, you will know: How to declare associations between Active Record models. How to understand the various types of Active Record...

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

–  
Regards,

T.Veerasundaravel.  
[http://tinyurl.com/25vma7h](http://tinyurl.com/25vma7h)  
@veerasundaravel

Sudhir V. wrote:

> Thanks For the Help Heinz S…  
> But i need To Know Is there anything with rails 2.3.5 because to check  
> wheather i have made any mistake in my application i created a sample  
> application , and again it was the same error i got .  
> waiting for your reply  
> and one more thing …i am only a couple of months old to Ruby On rails  
> .so please if possible suggest me how to make the associations between  
> tables in rails.

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 12:01pm UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/5 "2010-09-17T12:01:39Z")

</div>

Sorry But I guess I have read all The Associations …the only thing i  
want to know is there any problem with rails 2.3.5 because when i make  
the associations in 2.3.5 i get the same error  
undefined method `some method’ for nil:NilClass"

Veera S. wrote:

> If you are much interested in Rails Associations means, refer these  
> URLs.
> 
> [Active Record Associations — Ruby on Rails Guides](http://guides.rubyonrails.org/association_basics.html)  
> [ActiveRecord::Associations::ClassMethods](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)
> 
> –  
> Regards,
> 
> T.Veerasundaravel.  
> [http://tinyurl.com/25vma7h](http://tinyurl.com/25vma7h)  
> @veerasundaravel
> 
> Sudhir V. wrote:
> 
> > Thanks For the Help Heinz S…  
> > But i need To Know Is there anything with rails 2.3.5 because to check  
> > wheather i have made any mistake in my application i created a sample  
> > application , and again it was the same error i got .  
> > waiting for your reply  
> > and one more thing …i am only a couple of months old to Ruby On rails  
> > .so please if possible suggest me how to make the associations between  
> > tables in rails.

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 12:20pm UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/6 "2010-09-17T12:20:26Z")

</div>

On Fri, Sep 17, 2010 at 3:31 PM, Sudhir V.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Sorry But I guess I have read all The Associations …the only thing i  
> want to know is there any problem with rails 2.3.5 because when i make  
> the associations in 2.3.5 i get the same error  
> undefined method `some method’ for nil:NilClass"

You can use “rails console” to start up the RAILS console and look up  
the  
values of various objects and make a decision why you are getting null.  
Most probable reason why you are getting null is that “journel\_id” value  
is  
not set in Ledger records.

In RAILS console, do:

> Ledger.first  
> …observe the field values…, look wheher journel\_id has valid integer

> Ledger.first.journel  
> …if you get null, then, journel\_id is not correct. try to set it to a  
> valid jourenl

> lg = Ledger.first  
> lg.journel = Journel.first  
> lg.save!  
> Ledger.first.jourenl  
> …now you should not see null…

> > Regards,
> > 
> > > application , and again it was the same error i got .  
> > > “Ruby on Rails: Talk” group.  
> > > To post to this group, send email to removed\_email\_address@domain.invalid.  
> > > To unsubscribe from this group, send email to  
> > > removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > .  
> > > For more options, visit this group at  
> > > [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
Srikanth S.  
[http://www.srikanthps.com](http://www.srikanthps.com)  
@srikanthps

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 12:24pm UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/7 "2010-09-17T12:24:32Z")

</div>

On Sep 17, 11:01 am, Sudhir V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Sorry But I guess I have read all The Associations …the only thing i  
> want to know is there any problem with rails 2.3.5 because when i make  
> the associations in 2.3.5 i get the same error  
> undefined method `some method’ for nil:NilClass"

Unlikely. As Heinz said, the most likely explanation is that some of  
your ledgers don’t have a journel.

Fred

---

<div class="post-metadata">

**Author:** ![sudhirsb2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sudhirsb2003](https://www.ruby-forum.com/u/sudhirsb2003)\
**Post date:** [September 17, 2010, 12:22pm UTC](https://www.ruby-forum.com/t/problem-with-active-record-associations-showing-error-ple/195120/8 "2010-09-17T12:22:15Z")

</div>

I doubt there’s a problem with Rails 2.3.5

Fire up the console and try following:  
ledger = Ledger.first  
ledger.journel = Journel.first  
ledger.journel.journal\_name

This should work and if so the ledgers you’re calling in the view just  
doesn’t have a journel. If not something’s wrong with the whole thing 🙂
