NameError in Home#index

45 Views Asked by At

I am trying to display my post on my home page. But I get an error:

NameError in Home#index.

Here is the code:

before_action :set_stories

Home Controller:

def set_stories    
    @stories = List.where(user: [current_user])
end

Index View (index.html.erb):

<div class="d-flex flex-column gap-3">
    <!-- Story Section Start -->
        <% @stories.each do |stories_list| %>
        <%= render 'story/stories_list', stories_list: stories_list %>
<% end %>

Partial for Story List (_stories_list.html.erb):

<div class="card d-flex flex-row align-items-center gap-3 px-3" style="width: 25rem; height: 7rem; overflow-x:scroll;" >
<% @stories.each do |story| %>
    <% (0...1).each do %>    
        <%= render 'story/story', story: story %>
    <% end %>
    <% end %>
</div>

Partial for Story (_story.html.erb):

<div class="d-flex flex-column justify-content-center align-items-center">
  <div class="col-lg-4 col-md-6 col-sm-8 p-3 mb-4 profile-post"  style="height:20rem;position: relative">
    <%= link_to @list do %> 
      <div class="row">
        <% if list.file.attached? %>
          <% if list.file.image? %>
          <div class="img-fluid">
          <%= image_tag(list.file, class: "img-thumbnail rounded-circle border border-2 border-primary", style: "width: 3.5rem") %>
          </div>
          <% elsif list.file.video? %>
            <%= video_tag(url_for(list.file), class: "img-thumbnail rounded-circle border border-2 border-primary", style: "width: 3.5rem", autoplay: false, loop: false, muted: false, controls: true) %>
          <% end %>
        <% end %>
      </div>
    <% end %>
  </div>
</div>

I was able to get the listings to display however the layout is it is showing the data twice - I think this is the problem

<% @stories.each do |story| %>
<% (0...1).each do %>    
  <%= render 'story/story', story: story %>
  <% end %>
<% end %>
0

There are 0 best solutions below