When I try get all categories (index action) there is an error:
当我尝试获取所有类别(索引操作)时出现错误:
undefined local variable or method `json'
But in show action everything fine. All files has .jbuilder extension. Here is controller code:
但在展示行动一切都很好。所有文件都有.jbuilder扩展名。这是控制器代码:
def index
@categories = Category.all
end
# GET /categories/1
# GET /categories/1.json
def show
@category = Category.find(params[:id])
end
Stack trace:
堆栈跟踪:
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:in
block in render'
activesupport (3.2.11) lib/active_support/notifications.rb:125:ininstrument'
render'
actionpack (3.2.11) lib/action_view/template.rb:143:inapp / 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:在仪器'actionpack(3.2.11)lib / action_view / template.rb:143:inrender'
2 个解决方案
#1
72
Try to rename your file index.json.builder
to index.json.jbuilder
尝试将文件index.json.builder重命名为index.json.jbuilder
#2
0
You could also rename it to index.json.jpbuilder
and use this gem: https://github.com/bigjason/jpbuilder (if you want JSONP)
你也可以将它重命名为index.json.jpbuilder并使用这个gem:https://github.com/bigjason/jpbuilder(如果你想要JSONP)
#1
72
Try to rename your file index.json.builder
to index.json.jbuilder
尝试将文件index.json.builder重命名为index.json.jbuilder
#2
0
You could also rename it to index.json.jpbuilder
and use this gem: https://github.com/bigjason/jpbuilder (if you want JSONP)
你也可以将它重命名为index.json.jpbuilder并使用这个gem:https://github.com/bigjason/jpbuilder(如果你想要JSONP)