我创建了一个简单的演示应用程序,进行一些实验:
rails new rumba
rails g scaffold People name:string
然后我写了一个小程序来发出一个帖子请求:
require 'rest_client'
response = RestClient.post 'localhost:3000/people', :people => {:name => 'Joseph'}
puts response
到目前为止,它起作用并产生了一个新的人。我面临的唯一问题是我认为这不适用于heroku,因为我没有提供身份验证令牌:
Started POST "/people" for 127.0.0.1 at 2013-09-09 00:08:10 +0200
Processing by PeopleController#create as XML
Parameters: {"person"=>{"name"=>"Joseph"}}
WARNING: Can't verify CSRF token authenticity
←[1m←[35m (0.0ms)←[0m begin transaction
←[1m←[36mSQL (2.0ms)←[0m ←[1mINSERT INTO "people" ("created_at", "name", "upd
ated_at") VALUES (?, ?, ?)←[0m [["created_at", Sun, 08 Sep 2013 22:08:10 UTC +0
0:00], ["name", "Joseph"], ["updated_at", Sun, 08 Sep 2013 22:08:10 UTC +00:00]]
所以我的问题是如何在我的 RestClient.post 请求中提供身份验证令牌?