Serve a static JSON object file in rails

How do I serve a static JSON object from a file in rails? (I want to access it in an ajax call)?

What is the best method?

  • JavaScript: function not working without alert()
  • Callback function inside directive attr defined in different attr
  • Jquery/Ajax call with timer
  • Loading a readme from github?
  • Response for preflight has invalid HTTP status code 400
  • How to do AJAX POST cross-domain with custom headers
  • Submitting a form to a Rails server from jQuery using AJAX isn't working in IE11
  • How to return an array from an AJAX call?
  • Ajax heavy JS apps using excessive amounts of memory over time
  • load innerHtml of ajax loaded div
  • Trim Function Results
  • What is 'xmlhttp.setRequestHeader();' and in which situations is it used?
  • One Solution collect form web for “Serve a static JSON object file in rails”

    Just place what you want to render in a variable, then use render :json => variable
    There are sensible defaults for lists, dicts, etc…

    See this:
    http://guides.rubyonrails.org/layouts_and_rendering.html

    Item: “2.2.8 Rendering JSON”