我已经启动了一个新的rails 4应用程序,并希望将其用作API。这就是我得到的:
app/controllers/api/v1/teams_controller.rb
:
module Api
module V1
class TeamsController < ApplicationController
...
def show
@team = Team.find(params[:id])
end
...
end
end
end
app/views/api/v1/teams/show.json.jbuilder
:
team ||= @team
json.id team['id']
json.name team['name']
然后我得到一个空白页面。
但是,当我将render json: @team
添加到show
方法时,它会正常渲染。
有人知道JBuilder出了什么问题吗?
在将format: 'json'
添加到路由之前,我也遇到了同样的问题:
get '/api/stuff', to: 'stuff#show', format: 'json'
希望能有所帮助。