title: syntax error, unexpected end-of-input, expecting end — my code is missing an 'end' and I cannot figure out why
body: <h1>Error</h1>
  <p><a href="https://i.stack.imgur.com/w5xdU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w5xdU.png" alt="Error image" /></a></p>
  <p>Error in text:</p>
  <pre><code>D:/Projects/Web/RoR/ecommerce/app/controllers/search_controller.rb:46: syntax error, unexpected end-of-input, expecting end
  </code></pre>
  <p>As can be seen from the screenshot, the program is expecting (I think) an 'end' after the last line; at the very least, adding an extra 'end' removes the error message.</p>
  <p>However, I just don't understand why. More shouldn't be necessary. Am I missing the obvious here?</p>
  <p>It hurts me to put such a question here, but I'm about to tear my hair out.</p>
  <h1>Code</h1>
  <pre><code>class SearchController &lt; ApplicationController
    def index
    end
  
    def search
      all_books = Book.all
      all_authors = Author.all
      all_genres = Genre.all
      @filtered_books = []
  
      # perform the search 
      params[:search_items].split(',').each do |token|
  
        token = token.downcase.strip
  
        unless token.empty? do
          # look in books
          all_books.each do |book|
            if book.title.downcase.include?(token) then
              @filtered_books &lt;&lt; book
            end
          end
  
          # look in authors
          all_authors.each do |author|
            if author.full_name.downcase.include?(token) then
              @filtered_books &lt;&lt; author.books
            end
          end
  
          # look in genres
          all_genres.each do |genre|
            if genre.name.downcase.include?(token) then
              @filtered_books &lt;&lt; genre.books
            end
          end
        end # end for unless do
      end # end for params do
      
      # remove duplicates
      @filtered_books = @filtered_books.uniq
      render plain: @filtered_books
    end
  
    def show
    end
  end
  </code></pre>
  <h1>Attempted Solutions</h1>
  <p>I installed a Ruby linter VS Code extension, and it tells me the same thing as the error message on-screen, but following its advice leaves me with 2 <code>end</code>s on the same &quot;indentation level&quot;:</p>
  <pre><code>class SearchController &lt; ApplicationController
    def index
    end
  
    def search
      all_books = Book.all
      all_authors = Author.all
      all_genres = Genre.all
      @filtered_books = []
  
      # perform the search 
      params[:search_items].split(',').each do |token|
  
        token = token.downcase.strip
  
        unless token.empty? do
          # look in books
          all_books.each do |book|
            if book.title.downcase.include?(token) then
              @filtered_books &lt;&lt; book
            end
          end
  
          # look in authors
          all_authors.each do |author|
            if author.full_name.downcase.include?(token) then
              @filtered_books &lt;&lt; author.books
            end
          end
  
          # look in genres
          all_genres.each do |genre|
            if genre.name.downcase.include?(token) then
              @filtered_books &lt;&lt; genre.books
            end
          end
        end # end for unless do??
        end # end for params do??
      end
      # remove duplicates
      @filtered_books = @filtered_books.uniq
      render plain: @filtered_books
    end
  
    def show
    end
  end
  </code></pre>
  <p>I tried putting the &quot;fixed&quot; code (by the linter) through a beautifier in hopes I wasn't seeing something, but it leaves a mess:</p>
  <pre><code>class SearchController &lt; ApplicationController
      def index
      end
          def search
          all_books = Book.all
          all_authors = Author.all
          all_genres = Genre.all
          @filtered_books = []
                  # perform the search 
          params[:search_items].split(',').each do |token|
                          token = token.downcase.strip
                          unless token.empty? do
                  # look in books
                  all_books.each do |book|
                      if book.title.downcase.include?(token) then
                          @filtered_books &lt;&lt; book
                      end
                  end
                                  # look in authors
                  all_authors.each do |author|
                      if author.full_name.downcase.include?(token) then
                          @filtered_books &lt;&lt; author.books
                      end
                  end
                                  # look in genres
                  all_genres.each do |genre|
                      if genre.name.downcase.include?(token) then
                          @filtered_books &lt;&lt; genre.books
                      end
                  end
              end # end for unless do??
          end # end for params do??
      end
      # remove duplicates
      @filtered_books = @filtered_books.uniq
      render plain: @filtered_books
  end
  def show
  end
  end
  </code></pre>
  <p>Just what is going on?</p>