Reputation: 12601
here's my problem.. resource: user method: create
I call curl like this:
curl -X POST -H 'Content-type: text/xml' -d '<xml><login>john</login><password>123456</password></xml>' http://0.0.0.0:3000/users
but the params hash in rails look like this:
{"xml"=> {"login"=>"luca", "password"=>"123456"}}
I want it to look like this:
{"login"=>"luca", "password"=>"123456"}
I can get it to be like that if I pass the parameters on the url (...?login=luca&pas....), but that's not good...
any idea?
Upvotes: 3
Views: 3668
Reputation: 230
Hey I had this problem for a long time as well. I found out that you can do this -
Make a new defaults.rb inside the initializers directory: yourapp/config/initializers/defaults.rb
ActiveRecord::Base.include_root_in_json = false
Now the root should be gone from your json.
Upvotes: 1
Reputation: 54051
curl -X POST -d 'login=john&password=123456' http://0.0.0.0:3000/users
See also: Stack Overflow: How do I make a POST request with curl
Upvotes: 3
Reputation: 25659
curl -X POST -H 'Content-type: text/xml' -d '<login>john</login><password>123456</password>' http://0.0.0.0:3000/users
What does that get you?
After getting your comment, why not access it through params[:xml] in your controller, rather than params[:login] and params[:password]?
@user = User.authenticate(params[:xml])
That will pass login and password to your model.
Upvotes: 2