<table cellspacing=''0'' cellpadding=''0'' border=''0'' ><tr><td style="font: inherit;"><P>Sorry for the simplicity on this. I hope this makes for a quick response.</P> <P> </P> <P>I have two classes:</P> <P> </P> <P>class UserProfile < ActiveRecord::Base<BR> belongs_to :UserGroup<BR>end<BR></P> <P>class UserGroup < ActiveRecord::Base</P> <P> has_many :UserProfiles</P> <P>end</P> <P> </P> <P>I want to display the UserGroup.Name for an UserProfile instance.</P> <P> </P> <P>This snippet returns the correct User_Group id:</P> <P> </P> <P>@user_profile.User_Group_id</P> <P> </P> <P>This code seemed the most logical to me:</P> <P> </P> <P>@user_profile.UserGroup.Name</P> <P> </P> <P>but I get this error:</P><PRE><CODE>You have a nil object when you didn''t expect it! The error occurred while evaluating nil.Name</CODE></PRE><PRE><CODE>What should the call be?</CODE></PRE><PRE><CODE>Thanks in advance!</CODE></PRE></td></tr></table><br> <hr size=1>Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ "> Try it now.</a> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. <br> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> <br>
FYI, I figured this out. I shouldn''t have been using capital letters in my classes. But now, I''ve run into a different problem. These two classes: class UserProfile < ActiveRecord::Base belongs_to :UserGroup end class UserGroup < ActiveRecord::Base has_many :UserProfiles end become: class UserProfile < ActiveRecord::Base belongs_to :usergroup end class UserGroup < ActiveRecord::Base has_many :userprofiles end I''m not getting the error below when I make this call: <% for user_profile in @user_profiles %> ... <td><%=h user_profile.usergroup.Name %></td> ... ========Error=====uninitialized constant UserProfile::Usergroup Thoughts? On Feb 15, 12:24 pm, Steve Peters <stevepeter...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Sorry for the simplicity on this. I hope this makes for a quick response. > > > > > > > > I have two classes: > > > > > > > > class UserProfile < ActiveRecord::Base > belongs_to :UserGroup > end > > > > class UserGroup < ActiveRecord::Base > > > > has_many :UserProfiles > > > > end > > > > > > > > I want to display the UserGroup.Name for an UserProfile instance. > > > > > > > > This snippet returns the correct User_Group id: > > > > > > > > @user_profile.User_Group_id > > > > > > > > This code seemed the most logical to me: > > > > > > > > @user_profile.UserGroup.Name > > > > > > > > but I get this error: > > You have a nil object when you didn''t expect it! The error occurred while evaluating nil.NameWhat should the call be?Thanks in advance!Be a better friend, newshound, and know-it-all with Yahoo! Mobile.Try it now.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 15, 4:41 pm, stevepeters <stevepeter...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> FYI, I figured this out. I shouldn''t have been using capital letters > in my classes. But now, I''ve run into a different problem. > > These two classes: > class UserProfile < ActiveRecord::Base > belongs_to :UserGroup > end > > class UserGroup < ActiveRecord::Base > has_many :UserProfiles > end > > become: > class UserProfile < ActiveRecord::Base > belongs_to :usergroupShould be ''user_group''> end > > class UserGroup < ActiveRecord::Base > has_many :userprofilesand ''user_profiles'' Multiple words in the class name correspond to multiple words in the table and relationship names. Here''s another tip to preserve sanity: Follow the dictionary when deciding whether a name is one word or multiple words. This rule tells you to call the class ''UserGroup'' and the table ''user_groups'' instead of ''Usergroup'' and ''usergroups''. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---