0

I have been using RestClient to call the API, so here I am calling the DELETE method to delete one image:

@mposter_D = params[:mposter_D]
@mid_D = params[:mid_D]
req = Hash.new
req['mov'] = @mid_D

puts "....#{req.to_json}"
resource_pos = RestClient::Resource.new
Rails.application.config.sta_url+"/movi/pos/"+@mposter_D 
response_pos = resource_pos.delete req.to_json, :content_type => :json

After calling this I am getting this:

ArgumentError (wrong number of arguments (2 for 1)): in the last line of code
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user2342350
  • 101
  • 2
  • 13

3 Answers3

1

I was having the same problem. Apparently you cannot pass parameters from within the url when doing a delete method. (i.e. This will NOT work: http://example.com/resource?foo=bar&baz=qux)

If you need to add parameters to your delete request use the following format:

RestClient.delete 'http://example.com/resource', :params => {:foo => 'bar', :baz => 'qux'}

See the restclient docs section called Query Parameters

Patrick G.
  • 697
  • 7
  • 13
  • Where did you find that you can only pass a single url in a delete request? I would also like to pass authorization details `{:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}` and can't figure out if it's possible. Call would look like: `RestClient.delete "http://example.api.com/users/sign_out", {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}, :params => {:api_token => api_token, :user_id => user_id}` – Marklar Jun 09 '15 at 02:41
  • From the restclient docs they did it like this: # DELETE request with modified headers: `RestClient.delete 'http://example.com/resource', {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}` – Patrick G. Jun 09 '15 at 17:41
  • Thanks for the reply, to use both authorization header and params, the :params key is actually pulled out of the headers hash. `RestClient.get 'http://example.com/resource', {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g', :params => {:foo => 'bar', :baz => 'qux'}}`. https://github.com/rest-client/rest-client/issues/397#issuecomment-110527709 – Marklar Jun 10 '15 at 00:22
0

All I know about delete via rest_client is that, it takes only one parameter :

RestClient.delete 'http://demo.com/your_resourse'

you have to pass your url in that method. Thanks

Rails Guy
  • 3,836
  • 1
  • 20
  • 18
0

Try this:

RestClient.delete 'http://foo.com/your_resourse_id?#{req.to_query}'

Or:

RestClient.delete 'http://foo.com/your_resourse_id?mov=' + @mid_D
user2503775
  • 4,267
  • 1
  • 23
  • 41
  • here how can i pass the json and header value with this? – user2342350 Aug 06 '13 at 11:28
  • Try : RestClient.delete 'http://foo.com/your_resourse_id?#{req.to_query}', :content_type => :json, :accept => :json – user2503775 Aug 06 '13 at 11:58
  • Or this : http://rubydoc.info/gems/rest-client/1.6.1/RestClient#delete-class_method – user2503775 Aug 06 '13 at 12:23
  • RestClient.delete("http://foo.com/#{@mposter_D}?#{req.to_query}",:user => session[:user_name],:password => session[:password], :content_type => :json){ |response| puts "....#{response.code}" } got the response 500 here the problem is, cloud only take the url like "http://foo.com/#{@id}" and give that json in body, I have tested that in restclinet console. so if i am giving like http://foo.com/#{@mposter_D}?#{req.to_query}, how the cloud method read that? – user2342350 Aug 06 '13 at 13:29