I have a rails app where I have has_many and belongs_to association. But I am having problems while trying to retrieve the elements. My Models are Events, Comments and Votes. Events has multiple Comments and Votes. Of Course Comments and Voted belong_to one event.
My schema is
create_table "events",
t.string "etime"
t.integer "eid"
end
create_table "votes",
t.integer "eventid"
t.string "userid"
t.integer "event_id"
end
Associations:
class Event < ActiveRecord::Base
has_many :comments
has_many :votes
end
class Votes < ActiveRecord::Base
belongs_to :event
end
I am trying to view all the votes for the events. The controller action is:
@events = Event.all
@events.each do |event|
event.votes.each do |vote|
respond_to do |format|
format.html
end
end
end
View and error line:
<%= @vote.userid %>
I get an error "Undefined Method "userid" for vote". In my controller, I render my eventid and it worked. So it seems to be a problem when I do it in the view.. Any idea What I could be doing wrong? I am completely lost on this one