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

undefined local variable or method `json'

But in show action everything fine. All files has .jbuilder extension. Here is controller code:

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 instrument'
actionpack (3.2.11) lib/action_view/template.rb:143:in
render'

推荐答案

Try to rename your file index.json.builder to index.json.jbuilder

Json相关问答推荐

使用jolt删除空对象

在Go中,当字段可以根据其他字段具有不同的类型时,什么是正确的方法来卸载JSON?

为什么terraform不缩小这个策略JSON?'

最新版本的Deneb在数据溢出时不支持滚动

如何在数组抖动中按值分组

Jolt变换将字段移动到数组的每个元素中

使用JQ从jsonl文件中删除具有匹配键/值的行

Jolt 不打印任何东西

使用 jq 从字符串列表开始创建对象

如何按键过滤

JOLT 转换仅过滤一个字段

Nifi - 忽略(或删除)JSON 的第一个数字

ORA-01422: 精确提取返回的行数超过了与 json 对象组合的请求数

JSON Schema 与 XML Schema 的比较及其future

JSON extract\set 的 SQLite JSON1 示例

在 JavaScript 中从 Json 数据中删除反斜杠

以 unicode 将 pandas DataFrame 写入 JSON

带有 Jackson 的不可变 Lombok 注释类

使用 jQuery 和 JSON 填充表单?

用 JSON 编写 HTML 字符串