English 中文(简体)
创建JSON的用户
原标题:Create User in Devise from JSON

I m 努力将我的铁路3.1与我方言的用户认证连接起来。 我同用户一样,能够从申请中登记,然后我可以储存这些证书,以便日后登记。

使用休息 我这样做:

-(IBAction)registerUser:(id)sender {
    NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
                                                                self.email.text,
                                                                self.password.text,
                                                                self.confirmPassword.text,
                                                                nil]
                                                       forKeys:[NSArray arrayWithObjects:
                                                                @"email",
                                                                @"password",
                                                                @"password_confirmation",
                                                                nil]];

    [[RKClient sharedClient] post:@"/users.json" params:params delegate:self];
}

The /users.json url goes to: user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"} (according to rake routes). It appears that the post call accepts different formats, so I assume it will accept JSON. My Post request is serialized as JSON, and sent off. The server gets it, and this is the log:

Started POST "/users.json" for 129.21.84.10 at 2012-01-12 15:33:57 -0500
  Processing by Devise::RegistrationsController#create as JSON
  Parameters: {"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"[email protected]"}
WARNING: Can t verify CSRF token authenticity
  User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
   (0.3ms)  BEGIN
   (0.2ms)  COMMIT
   (0.2ms)  BEGIN
   (0.4ms)  ROLLBACK
Completed 422 Unprocessable Entity in 93ms (Views: 3.8ms | ActiveRecord: 10.2ms)

我有422个错误,我的用户没有产生。 我方言的答复是:Response:{“email”:[“can t be blank”],“password”:[“can t be blank”]。 但是,密码和电子邮件是空白,服务器是成功使用的。 因此,有些是工作权,我不敢肯定到哪里去。 我如何利用JSON创建用户?

感谢帮助!

最佳回答

你们的铁路公司正在以这种形式期望JSON:

{"user":{"email":"[email protected]", "password":"Test123", "password_confirmation":"Test123"}}

但是,由于停职停职,特区正在发出:

{"email":"[email protected]", "password":"Test123", "password_confirmation":"Test123"}

添加“用户”,你刚刚需要确定根基 与此类似:

RKObjectMapping *userSerializationMapping = [userMapping inverseMapping];
userSerializationMapping.rootKeyPath = @"user";
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:userSerializationMapping forClass:[User class]];
问题回答

我只想做同样的事情,即从一个“i”的手稿中创造用户。 我先看一下,它是由PPOSTing json做的治疗。

{"user":{"email":"[email protected]", "password":"Test123", "password_confirmation":"Test123"}}

并且:

http:// localhost:3000/users.json

申请表是申请表。

All standard Devise config.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签