Sudhir Vishwakarma
2010-Sep-17 07:45 UTC
Problem With Active Record. Associations Showing Error ..ple
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-17 09:07 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
Apparently one or more of your ledgers doesn''t have a journel? Try: <td><%=h ledger.journel.journal_name if ledger.journel %></td> to see the ones that don''t have journels. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sudhir Vishwakarma
2010-Sep-17 09:41 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Veera Sundaravel
2010-Sep-17 09:55 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
If you are much interested in Rails Associations means, refer these URLs. http://guides.rubyonrails.org/association_basics.html http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html -- Regards, T.Veerasundaravel. http://tinyurl.com/25vma7h @veerasundaravel Sudhir Vishwakarma wrote:> 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.-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sudhir Vishwakarma
2010-Sep-17 10:01 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
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 Sundaravel wrote:> If you are much interested in Rails Associations means, refer these > URLs. > > http://guides.rubyonrails.org/association_basics.html > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > > -- > Regards, > > T.Veerasundaravel. > http://tinyurl.com/25vma7h > @veerasundaravel > > > Sudhir Vishwakarma wrote: >> 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.-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Sep-17 10:07 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
On Sep 17, 11:01 am, Sudhir Vishwakarma <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> > > > > Veera Sundaravel wrote: > > If you are much interested in Rails Associations means, refer these > > URLs. > > >http://guides.rubyonrails.org/association_basics.html > >http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet... > > > -- > > Regards, > > > T.Veerasundaravel. > >http://tinyurl.com/25vma7h > > @veerasundaravel > > > Sudhir Vishwakarma wrote: > >> 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. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Srikanth Shreenivas
2010-Sep-17 10:07 UTC
Re: Re: Problem With Active Record. Associations Showing Error ..ple
On Fri, Sep 17, 2010 at 3:31 PM, Sudhir Vishwakarma <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>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...> > Veera Sundaravel wrote: > > If you are much interested in Rails Associations means, refer these > > URLs. > > > > http://guides.rubyonrails.org/association_basics.html > > > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > > > > -- > > Regards, > > > > T.Veerasundaravel. > > http://tinyurl.com/25vma7h > > @veerasundaravel > > > > > > Sudhir Vishwakarma wrote: > >> 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. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Srikanth Shreenivas http://www.srikanthps.com @srikanthps -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-17 10:22 UTC
Re: Problem With Active Record. Associations Showing Error ..ple
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 :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.