I'm just starting out on Rails and haven't been able to find a relationship.
I have 3 tables: Video, donations and users. A user can put X videos and each video can have several donations.
- In video I have
user_id
- In Donations I have the
user_id
andvideo_id
My models are:
class Donation < ActiveRecord::Base
belongs_to :user
belongs_to :video
end
class Video < ActiveRecord::Base
belongs_to :user
has_many :donation
end
class User < ActiveRecord::Base
has_many :video
has_many :donation
end
I can get the user of each video without problems:
video.user.name
The problem occurs when I want to get the title of the video of a donation:
<% @donaciones.each do |d| %>
<%= d.video.titulo %><br>
<% end %>
always gives me:
undefined method `titulo' for nil:NilClass
The title is in the table videos
, I only have 1 record.
Is there a way to be able to see the full query being performed on the error page?