Hi,
I''m experiencing a strange problem on an application this is in the
process of being converted from Rails 2.3 to 3.0.3. I have several
controllers that are rendering either HTML or JSON depending on the
requested format, using respond_to:
respond_to |wants|
wants.html
wants.json {render :json => "blah"}
end
One controller works just fine. The other is sending the wrong
content type header - "text/html" instead of
"application/json". If I
remove the respond_to block in the second controller, and just
render :json all the time, then the correct type is sent. There are
no apparent differences between the working and non-working
controllers except the model being retrieved from the database. I''ve
tried reducing the actions down to rendering just a string as JSON (as
seen above) and still have the same problem.
Does anyone have a suggest as to what could be happening? How can I
trace the response back through the Rails stack to perhaps see where
the content type is being set (or not set?)
I can provide more detail if needed.
Thanks!
Pete
--
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.
Pete Deffendol
2010-Dec-06 22:50 UTC
Re: render :json not setting content type (Rails 3.0.3)
It took a little while longer, but I found a supposedly undocumented gotcha in Rails 3 that was causing my problem. The controller in question had a private method "content_type" defined. Apparently that method is already defined for controllers, and overriding it was causing the problem with the MIME type. So, don''t define a content_type method in your controller. On Dec 3, 12:26 pm, Pete Deffendol <p...-fPKBWEOU8FaXDw4h08c5KA@public.gmane.org> wrote:> Hi, > > I''m experiencing a strange problem on an application this is in the > process of being converted from Rails 2.3 to 3.0.3. I have several > controllers that are rendering either HTML or JSON depending on the > requested format, using respond_to:-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.