ransack gem, ActiveResource and REST API

1.2k views Asked by At

I want to query to a rest api, passing paramateres in the link like ransack gem.

Is there any way to integrate the ransack gem, quering through a rails client (with activeresource) to a REST API?

I didn't find any manual about this.

1

There are 1 answers

0
Zubatman On

I would recommend adding this method:

BASE_URL = "http://yourwebsite.com/search?"

def generate_search_url(params)
    BASE_URL + params.to_query + "&api_key=#{your_api_key}"
end

By using the .to_query method you are able to encode the params you want to send, but it's more obscured than simply sending them in the request URL. I admit I am not terribly familiar with the ransack gem, but if you simply want to pass a JSON of your parameters to an API this is a good way to do just that