文字错误:
D:/Projects/Web/RoR/ecommerce/app/controllers/search_controller.rb:46: syntax error, unexpected end-of-input, expecting end
从截图中可以看出,程序期望(我认为)在最后一行之后有一个“结束”;至少,添加一个额外的“结束”会删除错误消息。
但是,我只是不明白为什么。更多的应该没有必要。我在这里错过了明显的东西吗?
在这里提出这样的问题让我很痛苦,但我要撕掉我的头发。
class SearchController < 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 << book
end
end
# look in authors
all_authors.each do |author|
if author.full_name.downcase.include?(token) then
@filtered_books << author.books
end
end
# look in genres
all_genres.each do |genre|
if genre.name.downcase.include?(token) then
@filtered_books << 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
我安装了一个 Ruby linter VS Code 扩展,它告诉我与屏幕上的错误消息相同的事情,但遵循它的建议让我end
在相同的“缩进级别”上有 2秒:
class SearchController < 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 << book
end
end
# look in authors
all_authors.each do |author|
if author.full_name.downcase.include?(token) then
@filtered_books << author.books
end
end
# look in genres
all_genres.each do |genre|
if genre.name.downcase.include?(token) then
@filtered_books << 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
我尝试通过美化器放置“固定”代码(通过 linter),希望我没有看到任何东西,但它留下了一团糟:
class SearchController < 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 << book
end
end
# look in authors
all_authors.each do |author|
if author.full_name.downcase.include?(token) then
@filtered_books << author.books
end
end
# look in genres
all_genres.each do |genre|
if genre.name.downcase.include?(token) then
@filtered_books << 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
到底是怎么回事?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句