0

I want to know a way using which a template/partial will always get rendered for all :get request having js/html format

I do not want to place it this inside a layout, as most of our request are js and wont use layout

The purpose here is, I will use this template to set some javascript global variables used throughout the javascript/coffeescript, for instance we want to know the role of the current user or whether current user is admin or not etc so this template will set those values/flags in gs globals etc

What am looking for is a hook into rails rendering engine, that at the end of last template or better before first template, I would like my template get rendered and set these js variables, may be similar to any middleware hook

Amol Pujari
  • 2,280
  • 20
  • 42

1 Answers1

0

Why would you not want to use layout? Layout does not need to be HTML. You can just have something like:

// layout/variables.erb
var foo = <%= JSON.dump(@foo)} %>;
<%= yield %>
Amadan
  • 191,408
  • 23
  • 240
  • 301
  • I will need to add this layout to many partials, we do use many js calls where these js wont render a common set of partials or even a single one, if thats was the case, I would not have raised this question. Now given that I do not have that choice – Amol Pujari Jul 04 '14 at 00:36