这里的这个新手正在用 Rails 上的 web 服务打他的头。也许有人可以减轻我的痛苦?
我创建了一个简单的 rails 应用程序,并生成了脚手架 MyRecords。然后我尝试使用以下代码在 irb 上创建记录:
测试WS.rb
require 'HTTParty'
class MyRecordCreate
include HTTParty
base_uri 'localhost:3000'
def initialize(u, p)
@auth = {:username => u, :password => p}
end
def post(text)
options = { :body => { name:text} }
self.class.post('/my_records', options)
end
end
response = HTTParty.get("http://localhost:3000/my_records/new.json")
print response
record = MyRecordCreate.new("","").post("test remote record")
print record
使用上面的代码,我设法创建了一条记录。问题是我的记录(只有“名称”列)是用空名称创建的!
对这个有什么建议吗?
我渴望将这种绝望一点一点地切碎。
感谢您的贡献。