It seems to_json is returning an incorrect format.I have a Product
model with id , title, description.
In ProductsController, in index I have
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml =>
@products.to_xml(:procs=>allprocs, :skip_instruct =>
true,:skip_types=>true,:except=>[:id,:created_at,:updated_at]
)
}
format.json { render :json =>
{:products=>@products.to_json(:only=>[:id,:title]) } }
end
end
It returns the result as
{"products":"[{\"product\":{\"title\":\"Cross
Stitch Design\",\"id\":
4}},{\"product\":{\"title\":\"Effective
Java\",\"id\":20}},{\"product
\":{\"title\":\"Thinking in
Java\",\"id\":22}},{\"product\":{\"title\":
\"Programming in
Java\",\"id\":23}},{\"product\":{\"title\":\"My
experiment\",\"id\":28}}]"}
It is escaping " is OK. But "products":"[{ ... the
javascript treats
it as a string because of ". can you please suggest any solution to
this problem.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.