I’ve got some javascript that needs to load a rails partial – I’d prefer not to repeat the partial’s HTML in the javascript file.
Is there a way to make this partial accessible via the browser url so JS can load it?
partial location:
shared/_search.html.erb
I would like to grab the view html with something like this:
example.com/shared/search.html
Can I explicitly route this or grab it locally via the file system?
I don’t want to have to create a controller just to render this partial for the JS.
You don’t need to create a new controller file. But you do need an action to respond to the incoming request from your JS.
That action can render a partial specifically if you want. You can also generalize the action by having the JS ask for the partial by name as one of the parameters to the action.
If the issue is that you need to rapidly service a zillion of these calls coming in and you don’t need the ActiveController machinery (you don’t want to create a controller instance for the request), you could use Rails Metal — http://railscasts.com/episodes/150-rails-metal
Added: Another option is to store a template file on your server (in public/assets etc). Then: