Pregunta

I have a trouble with request_via_redirect

How i use this method:

  def synchronize
    request_via_redirect(:post, synchronize_companies_path, params)
  end

And get an error:

NoMethodError (undefined method `request_via_redirect' for #<Companies::ApiController:0x00000006739a00>):

Anybody can explain what is wrong?

¿Fue útil?

Solución

Seems like you are using a rspec integration method. request_via_redirect, post_via_redirect and other methods like that are made to work with testing integration environment. Those functions only work inside a test/spec kind of file.

Try changing your code to the following:

def synchronize
    require "uri"
    require "net/http"
    Net::HTTP.post_form(URI.parse(synchronize_companies_path), params)
end

I am pretty sure that there's a better way of doing what you want to do. Some more information about your intentions should help.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top