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)
______________________________________________________________________________________________

--
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@googlegroups.com.
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.

Search Discussions

  • Bill Walton at Dec 9, 2011 at 3:32 pm
    Hi Krisnaraj,

    On Fri, Dec 9, 2011 at 4:05 AM, Krishnaraj KR
    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

    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 9, '11 at 10:39a
activeDec 9, '11 at 3:32p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Bill Walton: 1 post Krishnaraj KR: 1 post

People

Translate

site design / logo © 2021 Grokbase