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
答案 0 :(得分:0)
您需要为此create
操作创建新的视图文件,即create.json.jbuilder
下的views/pratices
。在那里写你的代码以返回json。
E.g:
# app/views/practices/create.json.jbuilder
json.practise do
json.attr1 @practice.attr1
json.attr2 @practice.attr2
json.attr3 @practice.attr3
end
请参阅此{/ p>的jbuilder
gem doc more information