views:

38

answers:

1

InvalidAuthenticityToken from rails for POST request Hi All I have a rails server running to which I make a POST request.

The dataset is defined as

Now per rails documentation in order to make a POST a request I need to set the add "authenticity_token" to the query string. So if for example the authenticity_token is "xxxxxxx", the final url should look like http://mywebsite.com/doSomething?aut..._token=xxxxxxx

I get the authenticity token from the server in the flashvars.

I have a user defined canvas attribute called auth_token which I use to store the authenticity token.

Below is the openlaszlo code I use to make the request.

var d = canvas.datasets.ds; var content = get_my_content(); d.setQueryParam('lzpostbody',content); d.setQueryString({authenticity_token : encodeURIcomponent(canvas.auth_token) }); d.doRequest

In this code the setQueryString call seem to clear out the query params. If I change the order of the setQueryString and setQueryParam calls the opposite happens.

The question is. Is there a way to set the query string without changeing/deleting the query params.

Thanks very much Puneet

+1  A: 

I don't know anything about OpenLaszlo, but my guess is that setQueryParam adds or modifies one param, whereas setQueryString overwrites the whole query string with the contents of the object.

Shouldn't you want to just add the authenticity token?

d.setQueryParam('lzpostbody', content);
d.setQueryParam('authenticity_token', encodeURIcomponent(canvas.auth_token));
Matchu
I dont think I can really do that because. 'lzpostbody' is special type of request param that is used to make raw POST requests. Per the Openlaszlo reference guid "Use of "lzpostbody" with a request that has more than one request parameter is undefined" So in effect in your example you are trying to use 2 params including lzpostbody and that is undefined. Appreciate your help though
Puneet Paul
@Puneet Paul - so you have to provide two parameters for the application to accept it, but you're only allowed to provide one? That sounds like the application has a flawed design.
Matchu