ROR return JSON with 406 Not Acceptable error

When we return JSON output using ‘render :json =>@profiles’, the
output will return the required results with a 406 error. How can
avoid that 406 Not Acceptable error ?

Function

def import
#json= params[:data]
@details = JSON.parse(json)
@profiles = Profile.where(@details)
respond_to do |format|
puts(render :json =>@profiles,:except =>
[:profileUpdatedDate,
:profileCreatedDate,:profileAddOrUpdate,:profileStatus]);
end
end

Output

Started GET “/webserviceapi/import” for 127.0.0.1 at Fri Dec 09
15:27:16 +0530 2
011
Processing by WebserviceapiController#import as HTML
←[1m←[36mProfile Load (1.0ms)←[0m ←[1mSELECT profiles.* FROM
profiles WHE
RE profiles.profileId = 'shanibskk123’←[0m
Completed 406 Not Acceptable in 102ms (Views: 7.0ms | ActiveRecord:
6.0ms)
[{“profileSex”:null,“profileFirstName”:null,“profileEducation”:null,“profileAge”
:null,“profileWeight”:null,“id”:
3,“profileId”:“shanibkk150467”,“profileRelation”
:null,“profileHeight”:null,“profilePassword”:“7c4a8d09ca3762af61e59520943dc26494
f8941b”,“profilePost”:null,“profileMobileNumber”:“9961977905”,“profileLastName”:
null,“profileEmail”:“shanibkk150467”}]
Started GET “/webserviceapi/import” for 127.0.0.1 at Fri Dec 09
15:30:33 +0530 2
011
Processing by WebserviceapiController#import as HTML
←[1m←[35mProfile Load (1.0ms)←[0m SELECT profiles.* FROM
profiles WHERE profiles.profileId = ‘shanibkk150467’
Completed 406 Not Acceptable in 49ms (Views: 15.0ms | ActiveRecord:
10.0ms)

Hi Krisnaraj,

On Fri, Dec 9, 2011 at 4:05 AM, Krishnaraj KR
[email protected] wrote:

When we return JSON output using ‘render :json =>@profiles’, the
output will return the required results with a 406 error. How can
avoid that 406 Not Acceptable error ?

This bit me yesterday. You’ve told rails that you’re going to respond
differently depending on what format the client requested by using
respond_to. But then didn’t tell rails what those response options
are. You need to put a format block around the response.

Function

def import
#json= params[:data]
@details = JSON.parse(json)
@profiles = Profile.where(@details)
respond_to do |format|
format.js{
puts(render :json =>@profiles,:except =>
[:profileUpdatedDate, :profileCreatedDate,:profileAddOrUpdate,:profileStatus]);
}
end
end

HTH,
Bill

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs