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 :
- Journel
class Journel < ActiveRecord::Base
has_many :ledgers
end
-
class Ledger < ActiveRecord::Base
belongs_to :journel
end
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.
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.
If you are much interested in Rails Associations means, refer these
URLs.
–
Regards,
T.Veerasundaravel.
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.
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
ActiveRecord::Associations::ClassMethods
–
Regards,
T.Veerasundaravel.
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.
On Fri, Sep 17, 2010 at 3:31 PM, Sudhir V.
[email protected]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 [email protected].
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Srikanth S.
http://www.srikanthps.com
@srikanthps
On Sep 17, 11:01 am, Sudhir V. [email protected] 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
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