On 25 July 2011 12:15, HenrySource <[email protected]> wrote: > environment: Ruby 1.9.2 Rails 3.0.9 win7-64 MySQL 5.1.53 > > HI, I’m working on a project. > It has three tables > and there are those name and relations. > > "room_type" 1 to many "guest" 1 to many "reservation" > > I need to access data from reservation model. > It works on the rails console by following command. > > "res =Reservation.find(1).guest.room_type.name" > > but in the page, it says "null" result. > > Controller: > > def show > @res=Reservation.find(params[:id]) > end > > Views: > <%= @res.guest.room_type.name %>
Read the error carefully and work out what it is that is nil. If you cannot work it out read the Rails Guide on debugging which will show various ways of finding out what is going on. In particular you can use ruby-debug to break into your code before the failing line and inspect the data to see what the problem is. If you still cannot work it out post the error message and stack trace here. Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

