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
2)
class Ledger < ActiveRecord::Base
belongs_to :journel
end
Thanks For the Help Heinz Strunk.
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"
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.
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