Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
Q&A

Post History

50%
+0 −0
Q&A Why skipped_deleted variable is undefined for a new file?

0 answers  ·  posted 3mo ago by Istiak‭  ·  deleted 11d ago by Istiak‭

Question ruby thread comments
#2: Post deleted by user avatar Istiak‭ · 2021-11-22T15:03:08Z (11 days ago)
#1: Initial revision by user avatar Istiak‭ · 2021-09-06T06:15:36Z (3 months ago)
Why skipped_deleted variable is undefined for a new file?
I had created new HTML.erb file to separate following lines. 

```html
<% pingable = get_pingable(@comment_thread) %>

<% skipped_deleted = 0 %>
<% comments = @comment_thread.comments %>
<% if params[:inline] == 'true' %>
  <% comments = comments.where(deleted: false).take 5 %>
<% end %>
<% comments.each do |comment| %>
  <% if comment.deleted && !(current_user&.is_moderator && params[:show_deleted_comments] == "1") %>
  <% skipped_deleted += 1%>
  <% next %>
  <% elsif skipped_deleted > 0 %>
  <div class="widget--body">
      <div class="deleted-comments">
          <p>
              <% if skipped_deleted == 1 %>
              Skipping <%= skipped_deleted %> deleted comment.
              <% if current_user&.is_moderator %>
              <a href="?show_deleted_comments=1">Show it anyway.</a>
              <% end %>
              <% else %>
              Skipping <%= skipped_deleted %> deleted comments.
              <% if current_user&.is_moderator %>
              <a href="?show_deleted_comments=1">Show them anyway.</a>
              <% end %>
              <% end %>
          </p>
      </div>
  </div>
   <% skipped_deleted = 0 %>
  <% else %>
    <% skipped_deleted = 0 %>
  <% end %>
  <div class="widget--body">
      <%= render 'comments/comment', comment: comment, pingable: pingable %>
  </div>
<% end %>
```

This is how I was rendering 
```ruby
<%= render 'comments/fetch_comment' %>
```

I got following error in thread page. 
```plain
ActionView::Template::Error: undefined local variable or method `skipped_deleted' for #<#<Class:0x000055945165c120>:0x00007f477151e608>
```

I was looking if some variable (called `skipped_deleted`) was declared in thread.html.erb. But, I couldn't find any. There's no variable which was used for indicating that `skipped_deleted` is integer. Although, why I am getting the above error in _fetch_comment.html.erb file? I don't have much more idea of ruby-on-rails.