JBuilder中未定义的局部变量或方法`json'

Mel*_*orn 26 json ruby-on-rails jbuilder

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

undefined local variable or method `json'
Run Code Online (Sandbox Code Playgroud)

但在展示行动一切都很好.所有文件都有.jbuilder扩展名.这是控制器代码:

def index
  @categories = Category.all
end

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

堆栈跟踪:

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

小智 91

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

  • 我还必须重启我的服务器. (10认同)