Hi.. I'm just getting started with Ruby and am creating an API that
will receive POST requests from its users.
I've got a "fake" user sending POST requests to the right controller in
my application, but I can't seem to access the data being posted. (the
create method in my controller is being invoked...so I know I'm
addressing the POST call correctly)
The data being posted is:
name=johnny&amount=928339
How do I capture this in the controller, create a new record and
populate the name and amount fields in my database?
I don't want to use XML...my data must be in the above format.
Hi.. I'm just getting started with Ruby and am creating an API that
will receive POST requests from its users.
I've got a "fake" user sending POST requests to the right controller in
my application, but I can't seem to access the data being posted. (the
create method in my controller is being invoked...so I know I'm
addressing the POST call correctly)
The data being posted is:
name=johnny&amount=928339
How do I capture this in the controller,
The POST data should be parsed by Rails and made available through the
params-method:
params[:name]
params[:amount]
create a new record and
populate the name and amount fields in my database?
The POST data should be parsed by Rails and made available through the
params-method:
params[:name]
params[:amount]
create a new record and
populate the name and amount fields in my database?
Model.create(...)
I tried using the params method, but it seems to be empty (I used
params[:trans].inspect and it's empty (trans is my controller)). I even
tried using request.env['RAW_POST_DATA'] to see if there was anything
there...and I'm getting nothing!
One other thing to consider is whether the poster is setting the
correct mime type - rails will parse the parameters differently
depending if its a multipart form, xml, good old application/x-www-
form-urlencoded etc...
Hey everyone thanks for all the help! I think I finally got it. I'm
not using a Ruby friendly post format, so I didn't want Ruby to assume a
post format and parse it into the hash automatically. In the end, I
used the following to get the raw post data...and now I'm going to parse
it out myself.