1

I have a resource there posting "host[name]=example.com" to it - creates a new host record with name example.com

The following works

curl http://localhost:3300/hosts.xml --request POST --data "host[name]=example.com"

Trying to do the same with activeresource fails

class Hosts < ActiveResource::Base
  self.site = "http://localhost:3300/"
  self.format = :xml
end

newhost = Hosts.new(:name => 'example.com')
newhost.save`

save returns true but no new host is created. Using find and destroy on existing host records works ok.

AFAIU Hosts.new(:name => 'example.com') does not generate the expected post data "host[name]=example.com". Is there a way I could make a new Host activeresource record to match the expected post data?

Piavlo
  • 126
  • 5

1 Answers1

0

Try:

newhost = Hosts.create(:name => 'example.com')

and see what happens.

also - it might be that Rails is confused by your model name. It might be expecting you to post to "hostss" as a pluralisation.

try calling it "Host" instead of "Hosts", then post to "hosts"

Taryn East
  • 27,486
  • 9
  • 86
  • 108