Search code examples
ruby-on-railspostmethodsactiveresource

Rails 3: ActiveResource custom method call - ClientError 414 - Work around?


I'm currently creating both the client and server app using ActiveResource for web servicing. The client has a long string (:history) that needs a conversion process done by the server.

Here, the client calls the post method on my object which extends ActiveResource::Base

active_resource.post(:convert, {:history => hh, :format => format})

This line errors complaining that the URI is too long:

ActiveResource::ClientError Failed. Response code = 414. Response message = Request-URI Too Large.

What other options do I have for sending "large" data ? Probably looking in the neighborhood of 2000 characters of data for the hh string above.

Thanks!


Solution

  • So the signature for the post method is:

    post(custom_method_name, options = {}, body = '')
    

    So, when you do:

    active_resource.post(:convert, {:history => hh, :format => format})
    

    It's putting your post variables in the options hash, which comes out in your query string for the post.

    What you want to do is:

    active_resource.post(:convert, nil, {:history => hh, :format => format}.to_json)