On all the pages of my app, I want a link to the JSON version of current page. Any neat tricks to do this? Where it got complicated was when additional '&' parameters were included in the URL.
So the urls would be transposed as:
'/users' => '/users.json'
'/users?page=1&per_page=5' => '/users.json?page=1&per_page=5'
Using the Chrome browser, go to the url with the json, then right click, then 'Inspect'. That brings up the Chrome devtools ui. From there go to 'Sources' and you will see the json file in the list. Then right click and you will be able to click 'Save as'.
getJSON method loads JSON-encoded data from a server using a GET HTTP request. This is the method signature. The url parameter is a string containing the URL to which the request is sent. The data is a plain object or string that is sent to the server with the request.
From HTML to JSON allows loading the Website URL which has tables converting to JSON. Click on the URL button, Enter URL and Submit. Parsing HTML into JSON supports loading the HTML File to transform to JSON. Click on the Upload button and select File.
Json url-encoder tool What is a json url-encoder? This tool converts JavaScript Object Notation (JSON) data to URL-encoding. All special URL characters get escaped to percent-number-number format. Json url-encoder examples Click to use. URL-escape a JSON Array.
try this :
polymorphic_path( @user, :format => :json )
(as seen in this API doc)
alternatively :
user_path( :id => @user.id, :format => :json )
Attribution for this answer from Get url for current page, but with a different format, with modifications:
Helper:
def current_url(new_params)
url_for params.merge(new_params)
end
Link:
<%= link_to "JSON of this page", current_url(:format=>:json)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With