我的控制器中有这个:
class TeamsController < ApplicationController
respond_to :json
def index
@teams = Teams.all
respond_with @teams
end
def show
@team = Teams.find params[:id]
respond_with @team
end
这就是我的观点:
<%= render partial: "team", object: @team %> #file-show.json.erb
[<%= render partial: "team", collection: @teams, spacer_template: "comma" %>] #file-index.json.erb
<%= @team.to_json.html_safe %> #file- _team.json.erb
但是 team.json 的响应总是 [null, null, null] 而 teams/1.json 的响应是正确的 {"id"...} 知道我做错了什么吗?