Accepted answer

1. am i correctly rendering json in the controller?

i don't think so. i would also send a status and you need to tell what json it is. so i would go like:

def percent
  @series.each do |series|
  render status: 200, json: @series.as_json  

2. should i be calling a url in the script or a file (since i'm using a localhost server)?

a url, always a url. you won't be able to access a file. and your url seems correct.

3. i suspect there are others, e.g., should the percent method be in the before action in the controller?

it depends on what you are doing. if you want to respond with the percent method generated json by calling /seriesroute, you need to call percent in the index method. if you want an explicit call to /percent you just need to add it to the routes and you are good to go. btw, you did change the routes file for this, right? you should at least have a get available for the series controller, or if you want full crud, a resource should be there. also, i think you should keep with the convention of having the model name on the singular form, and your has_many: series, doesn't make sense to me. what are you trying to achieve there? if a serie has_may series, then you should have a serie_id in the model and also a belongs to.

hope this helps somehow.

Related Query