I would like to render only certain pins of my rails app on a page. Pins has a specific id. And I would like to render for example pin with id: 2 and 3 on a page and render pins with id 4 and 4 on an other page.
So i tried to implement this code on my controller in: app/controller/pin_controller.rb
def mypage
@pin = Pin.find(2)
@pin = Pin.find(3)
end
And in my app/views/pins/mypage.html.erb I inserted the app/views/pins/index.html.erb
to make it short it looks like this:
<% @pins.each do |pin| %>
<%=link_to pin_path(pin) do %>
<%= pin.description %>
<% end %>
<% end %>
I have a method error saying that there is no method: each:
undefined method `each' for nil:NilClass
And of course if I get rid of this each method: the page only render one pin from the two pins I want to render.
Any ideas how to fix this?
You haven't defined @pins
anywhere.
def mypage
@pins = Pin.where(id: [2,3])
end