2011-10-18 21 views
0

私は以下のjsonオブジェクトの配列を持っています。jsonオブジェクトのフィルタ配列

[{"template":{"title":"title 1"}},{"template":{"title":"title 1"}},{"template":{"title":"title1111"}},{"template":{"title":""}},{"template":{"title":""}},{"template":{"title":"this is the title"}},{"template":{"title":"title232"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"title with msg"}},{"template":{"title":"this is a title"}},{"template":{"title":"this is a title"}},{"template":{"title":"this is a title"}},{"template":{"title":"some title"}},{"template":{"title":"some title"}},{"template":{"title":"some title"}},{"template":{"title":"some title"}}] 

私は、この配列は非常に基本的に私はjsの応答内のテンプレートのプロパティをしたくない

[{'title': 'some title'}, {'title': 'some other title'}, ...] 

のようになりたいです。 私は

@templates = Template.find_all_by_user_id(current_user.id, :select=>'title', :conditions=>"title is not null") 

@templates.to_jsonが私にJSONのこの配列

任意の提案オブジェクトを与えるものである以下のレールコードからこれを取得していますか?

答えて

0

私はこのケースでは、あなただけのTemplate秒のあなたのコレクション全体の属性を収集して行うことができると思う:

@templates = Template.find_all_by_user_id(current_user.id, :select=>'title', :conditions=>"title is not null").collect(&:attributes) 

(行の末尾に追加.collect(&:attributes)を参照するには右にスクロール。)

関連する問題