How did you write your Business and User models? What you are trying to do is as simple as a relation between User and Business model. And i guess it should be like the following:
class User < AR::B has_many :businesses # or # has_one :business end class Business < AR::B belong_to :user end Now if you have these setup as expected then what about your yml files? Did you made the exact relationship there? If you have businesses.yml and users.yml then a business object should have a user_id which should refer a user id from users.yml With a proper relation with user_id of businesses table with id of users table would return a user object if you call business.user and then you can call whatever method of that user object. However, could you please explain what is the user.login method doing here?? As you said > > foreign key e.g. it shows 'Graham' not 1 It should be like user.name or user.first_name or something else. But login method doesnt seem that intuitive or im missing something? Let me know the status... Samiron paul http://samironpaul.blogspot.com/ On Apr 10, 6:52 pm, Graham Farrell <li...@ruby-forum.com> wrote: > Hi all, > > I'm hoping someone can help me here I'm trying to carry out functional > testing, my IDE is NetBeans 6.8 and I've found that any tests on > controllers who have to deal with related data are failing. > > I've got a controller called business that hold the details of a > business along with its owner which is a user created using authlogic. > > In the get_index, and show_business sections of the test I'm getting an > ActionView error because I've changed the related view to display the > related data not the actualyforeign > > foreign key e.g. it shows 'Graham' not 1 > > The errors reported are > > test_should_get_index(BusinessesControllerTest): > ActionView::TemplateError: undefined method `login' for nil:NilClass > On line #24 of app/views/businesses/index.html.erb > > 21: <td><%=h business.country %></td> > 22: <td><%=h business.longitude %></td> > 23: <td><%=h business.lattitude %></td> > 24: <td><%=h business.user.login %></td> > 25: <td><%= link_to 'Show', business %></td> > 26: <td><%= link_to 'Edit', edit_business_path(business) %></td> > 27: <td><%= link_to 'Destroy', business, :confirm => 'Are you > sure?', :method => :delete %></td> > > test_should_show_business(BusinessesControllerTest): > ActionView::TemplateError: undefined method `login' for nil:NilClass > On line #38 of app/views/businesses/show.html.erb > > 35: > 36: <p> > 37: <b>Business Owner:</b> > 38: <%=h @business.user.login%> > 39: </p> > 40: > 41: <%= link_to 'Edit', edit_business_path(@business) %> | > > I am also getting a run time error on the get_new test as it can't save > a record because there is no logged in user. > > I've read that these failures are normal because of the changes I made > ocurred after ROR created the test files but not how to resolve the > issues. > > Can anyone give me some pointers on this??? > > Thanks, > > Graham > -- > 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.