This is my controller called static_pages:-
class StaticPagesController < ApplicationController #StaticPagesController is a ruby class that inherits from ApplicationController
def home
end
def genre
@genre=Genre.all
@book=Book.find_by(genre_id:1)
end
def accessories
end
def aboutus
end
def contactus
end
end
#home, genre and accessories are actions of the controller
This is a snippet of my view genre.html.erb:
<% @genre.each do|genre|%>
<tr>
<td><%=genre.genre_id %></td>
<br>
<td><%=genre.genre_name %></td>
<br>
<td><%=genre.description %></td>
<br>
<br>
</tr>
<% end %>
<% @book.each do|book|%>
<tr>
<td><%=book.book_name %></td>
<br>
<td><%=book.pages %></td>
<br>
<td><%=book.stock %></td>
<br>
<td><%=book.synopsis %></td>
<br>
<td><%=book.mrp%></td>
<br>
<td><%=book.author %></td>
<br>
<td><%=book.publisher %></td>
<br>
<td><%=book.rating %></td>
<br>
<td><%=book.genre_name%></td>
<br>
<td><%=book.discount %></td>
<br>
<br>
</tr>
<% end %>
I'm getting an error for the book portion when I open the genre view. It says that undefined method `each' for #Book:0x007f014ab326d8. I'm not sure why I'm getting this error because I copy pasted the thing from the genre part and that's not showing an error so why is this?