30

当我尝试获取所有类别(索引操作)时出现错误:

undefined local variable or method `json'

但在表演中一切​​都很好。所有文件都有 .jbuilder 扩展名。这是控制器代码:

def index
  @categories = Category.all
end

# GET /categories/1
# GET /categories/1.json
def show
  @category = Category.find(params[:id])
end

堆栈跟踪:

app/views/categories/index.json.builder:1:in _app_views_categories_index_json_builder___502133872307116590_70140532925300' actionpack (3.2.11) lib/action_view/template.rb:145:inblock in render '
activesupport (3.2.11) lib/active_support/notifications.rb:125:in render'instrument'
actionpack (3.2.11) lib/action_view/template.rb:143:in

4

2 回答 2

111

尝试将您的文件重命名index.json.builderindex.json.jbuilder

于 2013-03-18T11:59:59.113 回答
0

您也可以将其重命名为index.json.jpbuilder并使用此 gem:https ://github.com/bigjason/jpbuilder (如果您想要 JSONP)

于 2014-11-20T17:27:58.043 回答