Friday, December 9, 2011

Re: [Rails] ROR return JSON with 406 Not Acceptable error

Hi Krisnaraj,

On Fri, Dec 9, 2011 at 4:05 AM, Krishnaraj KR
<krishnaraj.icafs@gmail.com> 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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate