On Jueves, 28 de junio de 2012 09:20:43 Gloufy escribió:
> Hi everybody,
> 
> I want to export a model ton JSON with relationships but i don't want all
> the attributes of the object from the relationship... because it's to
> heavy...
> 
> Ex :
> models :
> 
> class Project < ActiveRecord::Base
> 
>   belongs_to :type
> 
>  #Attribute for project :id, :title
> 
> end
> 
> class Type < ActiveRecord::Base
> 
>   has_many :Projects
> 
>  #Attribute for Type :id, :title,:active,:updated_at,:created_at
> 
> end
> 
> controller :
> 
> class ProjectsController < ApplicationController
> 
>     activescaffold :project
> 
>   def list_respond_to_json
> 
>    @records.to_json(:only=>[:id,:title],:include=>[:type])
> 
>   end
> 
> end
> 
> The results is :
> 
> {
> 
>    - "type":{
>       - "created_at":"2007-04-20T00:00:00Z",
>       - "updated_at":"2011-08-14T16:07:45Z",
>       - "id":58,
>       - "title":"Série"
>    },
>    - "type_id":58,
>    - "id":791,
>    - "title":"Toto"
> 
> }
> 
> 
> but i would like to have :
> 
> {
> 
>    - "type":{
>       - "id":58,
>       - "title":"Série"
>    },
>    - "type_id":58,
>    - "id":791,
>    - "title":"SÉRIE"
> 
> }
> 
> how i can do that ?


@records.to_json(:only=>[:id,:title],:include=>{:type => {:only => [:id, 
:title]}})


> 
> Thanks for your help
> 
> Gloufy

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to