0
votes

I've created simple ROR app on Heroku's server and I want to add product using RUBY's script:

require 'rubygems' require 'rest_client'

RestClient.post 'http://falling-ice-5948.herokuapp.com/products/new', :title => 'TESTTESTTEST', :description => "MYTESTTESTTESTTEST", :image_url => "TESTTESTNULL.jpg", :price => 4.50

There's my page:

http://falling-ice-5948.herokuapp.com/products/new

When I run my script it gives me an error:

ruby postEasy.rb /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in return!': 404 Resource Not Found (RestClient::ResourceNotFound) from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in process_result' from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in transmit' from /usr/lib/ruby/1.8/net/http.rb:543:instart' from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in transmit' from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in execute' from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in execute' from /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient.rb:72:in post' from postEasy.rb:4

Any ideas?

Thanks in advance

3
Do you just want to create a product? If so, you could also do it in the rails console on heroku with $ heroku console.tbuehlmann
I want to create a ruby's scrpit which do it automatically. Do you undestand?ruhungry
So you actually just want to seed your database with records, right?tbuehlmann
Almost...Fe: I'll give you this script and you can use it for add your products. maybe it's important is on Heroku's server...ruhungry
Why would you do that at all? Is there any good reason to add products via some kind of HTTP API?tbuehlmann

3 Answers

1
votes

I don't know the details of your app but I would expect you to call the POST request on http://falling-ice-5948.herokuapp.com/products/ not http://falling-ice-5948.herokuapp.com/products/new.

GET http://falling-ice-5948.herokuapp.com/products/new would retrieve a form to create a new record.

1
votes

Check the output of rake routes. That will show the methods for the routes you have setup and the methods available. I suspect the /products/new will show as a GET whilst /products as a POST is what you actually want be doing.

BTW, this would have occurred locally too so it's not anything to do with Heroku.

1
votes

You will need to nest the params in the RestClient.post method. You're most likely looking for params[:product] in your action, but there won't be any data for that. I tested on your heroku app, sorry for that, but this will work (as it does for me):

RestClient.post 'http://falling-ice-5948.herokuapp.com/products',
  :product => {
    :title => 'foobarbazfoobarbaz',
    :description => "foobarbazfoobarbaz description",
    :image_url => "foobarbazfoobarbaz.jpg",
    :price => 42.00
  }