create.json.jbuilder 没有返回对象?
create.json.jbuilder not returning object?
def create
@practice = Practice.new(practice_params)
if @practice.save && @practice.start
respond_to do |format|
format.html { redirect_to practice_learnings_path(@practice) && return }
format.json
end
else
redirect_to practices_path
end
end
//create.json.jbuilder
json.practice @practice
您需要为此 create
操作创建新的视图文件,即 create.json.jbuilder
在 views/pratices
下。将您的代码写到 return json。
例如:
# app/views/practices/create.json.jbuilder
json.practise do
json.attr1 @practice.attr1
json.attr2 @practice.attr2
json.attr3 @practice.attr3
end
请参阅 jbuilder
gem 文档 more information
def create
@practice = Practice.new(practice_params)
if @practice.save && @practice.start
respond_to do |format|
format.html { redirect_to practice_learnings_path(@practice) && return }
format.json
end
else
redirect_to practices_path
end
end
//create.json.jbuilder
json.practice @practice
您需要为此 create
操作创建新的视图文件,即 create.json.jbuilder
在 views/pratices
下。将您的代码写到 return json。
例如:
# app/views/practices/create.json.jbuilder
json.practise do
json.attr1 @practice.attr1
json.attr2 @practice.attr2
json.attr3 @practice.attr3
end
请参阅 jbuilder
gem 文档 more information