Reputation: 677
Currently passing retrieved data using redirect_to
which uses GET
. Since in some cases data set is large, URI is too long and throws Bad Request
error.
All online research says its a bad idea to pass data in GET body. Is there a better way to pass data to another controller?
Code Block
def create
response_body = http_get('/data/I/want')
parsed_result = JSON.parse(response_body)
check_response(parsed_result)
redirect_to controller: :search_results, action: :index, results: parsed_result
end
end point called in create
is search results so need to check if results are empty before redirecting and passing the data. I omitted this part from the code block
Upvotes: 0
Views: 201
Reputation: 1923
Any reason to put these code in create
method? From my point of view, your code doesn't really create anything. It is just get some JSON data from a remote URL and redirect to search_results#index
. Why not just load the JSON in search_results#index
directly?
Update
It is too generous to use more than 3 routes for a search action. I have two suggestions:
Search in remote JSON if you can control it. Just pass the searching keyword in URL and let remote resolve it.
If you cannot control the remote JSON, do the search with AJAX call. In your search_results#index
, makes an AJAX call to your something like search#new
JSON route and fetch the filtered result.
Upvotes: 1