Hi everyone i am making an app with a backend in rails, i need to create a user from an ajax request and the server have to return a json object with the new user saved.
This is my code of rails
class UsersController < ApplicationController
def nuevo_usuario
@u = User.new(params[:user])
@u.save
respond_to do |format|
format.json { render :json => @u }
end
end
end
And this is the code of javascript
$.post("http://0.0.0.0:3000/users/nuevo_usuario.json", $("#resgistro-form").serialize(), function(data){});
And the server respond with this
Started POST "/users/nuevo_usuario.json" for 127.0.0.1 at 2013-06-14 10:17:22 -0500
Processing by UsersController#nuevo_usuario as JSON
Parameters: {"user"=>{"user"=>"prueba", "mail"=>"prueba@gmail.com", "password"=>"[FILTERED]"}}
WARNING: Can't verify CSRF token authenticity
(0.5ms) BEGIN
SQL (72.1ms) INSERT INTO "users" ("created_at", "mail", "password", "updated_at", "user") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["created_at", Fri, 14 Jun 2013 15:17:22 UTC +00:00], ["mail", "prueba@gmail.com"], ["password", "preuba"], ["updated_at", Fri, 14 Jun 2013 15:17:22 UTC +00:00], ["user", "prueba"]]
(18.2ms) COMMIT
Completed 200 OK in 395ms (Views: 1.1ms | ActiveRecord: 310.0ms)
I don't receive the json object that i send with rails.
if you need more information just tell me, thank you :)