내 레일 앱에서 acts_as_taggable_on을 사용하고 있습니다. 내 모델의 to_json 표현에이 태그를 표시하고 싶습니다.모델의 to_json 출력에 acts_as_taggable_on 태그 포함
{"created_at":"2012-02-19T03:28:26Z",
"description":"Please!",
"id":7,
"points":50,
"title":"Retweet this message to your 500+ followers",
"updated_at":"2012-02-19T03:28:26Z"}
을 ... 그리고 나는이 같은보고를하고 싶습니다 : 예를 들어
내 모델의 인스턴스의 to_json은 다음과 같습니다
{"created_at":"2012-02-19T03:28:26Z",
"description":"Please!",
"id":7,
"points":50,
"title":"Retweet this message to your 500+ followers",
"updated_at":"2012-02-19T03:28:26Z"
"tags" :
{"id":1,
"name":"retweet"},
{"id":2,
"name":"twitter"},
{"id":3,
"name":"social"}
}
내 컨트롤러 코드를 스캐 폴딩이 제공하는 기본값입니다.
def show
@favor = Favor.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @favor }
end
end
템플릿의 @ favor.tags에 이미 액세스 할 수 있습니다. @ favor.tags.to_json은 예상대로 작동하지만, @ favor.to_json을 출력 할 때 데이터가 포함되어야했습니다.