Hello i got this: <%Payment.find_all.each do |p|%> <li><a href="#"><%=p.member.name%>-<%=p.payer_id%></a></li> <%end%> it throw : You have a nil object when you didn''t expect it! The error occurred while evaluating nil.name but if i do the same in the script/console it just do it fine, but at the end of all it throw the same thing: i got: class Payment < ActiveRecord::Base set_table_name :payments belongs_to :member, :foreign_key=>:userid end class Member < ActiveRecord::Base set_primary_key :userid has_many :payment, :foreign_key=>:userid 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oh sorry, but finally i got the mistake, is that in DB some records doesn''t match with the userid in member and this was throwing me this error, i just get in touch with this: <%Payment.find_all.each do |p|%> <li><a href="#"><%=p.member.name if p.member%>-<%#=p.payer_id%></a> <span class="published_at">Feb 9, 2006</span></li> <%end%> Well now i can eat :D bye -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8/29/07, Edgar Gonzalez <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello i got this: > > <%Payment.find_all.each do |p|%> > <li><a href="#"><%=p.member.name%>-<%=p.payer_id%></a></li> > <%end%> > it throw : > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.namethis means that it couldn''t find a member record for that particular instance of a payment object. So for that payment object, userid would be nil, which means you can''t dereference it to obtain a user. A few comments about your code: 1) don''t use find_all, it''s been deprecated. Use Payment.find(:all) instead 2) put your finders in your controller, that''s where they belong. Use @payments = Payment.find(:all) and then in your view do something like <% @payments.each do |payment| %>> but if i do the same in the script/console it just do it fine, but at > the end of all it throw the same thing: > > i got: > > class Payment < ActiveRecord::Base > set_table_name :payments > belongs_to :member, :foreign_key=>:userid > endyou don''t need to use set_table_name here, the associated table name will by default be called ''payments'' the rails convention for foreign key naming is to use classname_id. So you should get into the habit of using user_id to reference a User object. In this case it doesn''t really matter, but you might as well follow convention. Adam --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey thanks a lot Adam, very constructive answer, relly thanks, good luck -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---