Jump to content

The ultimate community for Ruby on Rails developers.


Rails 4 update data using xml and jquery

Rails4 xml jquery put

  • Please log in to reply
1 reply to this topic

#1 reyntjensw



  • Members
  • 6 posts

Posted 01 February 2014 - 07:14 PM



I'm trying to automaticly update data using a ajax call out of jquery.

When an object gets moved, this code is being executed:


This is my jquery code

      type: "PUT",
      url: "/devices/2328.xml",
    data: '<device><name>test</name></device>',
      contentType: 'application/xml', // format of request payload
      dataType: 'html', // format of the response

My controller looks like this:

  def update
    @device = Device.find(params[:id])
    if @device.update_attributes(device_params)
      respond_with @device
      render :action => 'edit'
    def device_params

In my log I can see the request comming in, but nothing really happens, see at the bottom Completed 204 No Content
I'm also noticing that the value that I'm passing cannot be found at the parameters part of the log

Started PUT "/devices/2328.xml" for at 2014-02-01 19:10:33 +0100
Processing by DevicesController#update as XML
  Parameters: {"id"=>"2328"}

  Device Load (0.4ms)  SELECT `devices`.* FROM `devices` WHERE `devices`.`id` = 2328 LIMIT 1
   (0.1ms)  BEGIN
   (0.1ms)  COMMIT
Completed 204 No Content in 9ms (ActiveRecord: 0.6ms)

I can't really figure out what is wrong.

Does anyone have a clue?

#2 Bharat Soni

Bharat Soni


  • Members
  • 55 posts
  • LocationAhmedabad

Posted 15 February 2014 - 05:12 AM

Which type response the method will return ?


According to your code i think this will return response in xml format.


So you should do like this, it may will help you.......

respond_to do |format|

If this will not work for you then i have gem.


Please read about the gem name "rabl"

Fun with Ruby on Rails

Also tagged with one or more of these keywords: Rails4, xml, jquery, put

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users