How to send a Json in order to make an update in Rails?

I am trying to make an update between flex and rails with something like this:

// TODO Auto-generated method stub
var strXml:XML = <test>
<test_id>{txtMarketId.text}</test_id>
<market_name>{txtMarketName.text}</market_name>
</test>;

req = new URLRequest("http://localhost:3000/tests/"+market_id);
jrwloader  = new URLLoader();
params = new URLVariables();
req.data = strXml.toString();                               
req.method = URLRequestMethod.POST;                                                         
req.requestHeaders.push(new URLRequestHeader("X-HTTP-Method-Override", URLRequestMethod.PUT));                                                          
jrwloader.load(req);

In my rails app I got this:

Started PUT "/markets/2" for 10.10.10.10 at 2012-09-08 18:37:24 +0000
Processing by TestController#update as */*
  Parameters: {"test_id:2, market_name:test"=>nil, "id"=>"2"}
WARNING: Can't verify CSRF token authenticity
  Market Load (0.2ms)  SELECT `tests`.* FROM `test` WHERE `test`.`test_id` = 2 LIMIT 1
   (0.1ms)  BEGIN
   (0.1ms)  COMMIT
Redirected to http://localhost:3000/tests/2
Completed 302 Found in 3ms (ActiveRecord: 0.4ms)

I think I am close to the answer but I cannot set the new data into the database.

Answers


You should add CSRF token to your request.

Here is more on the topic: http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf


I solve it! The main issue it was just to add one line in my request. So at the end I got something like this:

req = new URLRequest("http://localhost:3000/tests/"+market_id);
jrwloader  = new URLLoader();
params = new URLVariables();
req.data = strXml.toString();                               
req.method = URLRequestMethod.POST;                                                         
req.requestHeaders.push(new URLRequestHeader("X-HTTP-Method-Override", URLRequestMethod.PUT));                                                          
**req.requestHeaders.push(new URLRequestHeader("Content-type", 'application/xml'));**         jrwloader.load(req);

thanks all!


Need Your Help

cassandra load distribution - uneven 1.2.8

cassandra ycsb

I am having a 4 node cluster setup of apache-cassandra-1.2.8 and trying to load about a 25 million of records. The cluster is setup with the default (murmur) partitioning and assigned tokens based ...

jQuery outputting NaN

jquery nan

For some reason the code is outputting NaN on the website, but its working on the fiddle.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.