1

I know this is probably easy but it doesn't look like it's working. I have three views in my Books folder (index, order, and show). I need to apply a script to each of the pages that have something like:

<script>
 !(function() {
  var t;
  if (((t = windo.driftt = window.drift = window.driftt || []). !t.init))
   return t.invoked?
   void(
    window.console &&
    console.error &&
  drift.load("lettersandnumbers");
</script>

My thought was to create a book.js file under app > assets > javascripts. Copy/paste everything between script into book.js. Then update my index, show, and order to:

<script>
 $(document).ready(app.book);
</script>

Is this correct? Or is there a better way to have my script hit all of my views under Books?

Jake
  • 1,328
  • 1
  • 21
  • 51
  • 2
    You should use the `layout` file you defined for the `books` namespace. Maybe you haven't specified a layout for those pages and just use the "application layout" (same file for all), in that case you might want to define a sub-layout that output this js `script` tag(s) and then call the application layout. – MrYoshiji Feb 26 '18 at 15:28
  • So your recommendation is to actually do like a script partial under layout then render the partial? – Jake Feb 26 '18 at 15:29
  • yep, you can use `content_for` and `content_for?` to help you out (see one of my answers on the topic: https://stackoverflow.com/questions/16822775/difference-between-render-and-render-partial-and-yield) – MrYoshiji Feb 26 '18 at 15:34
  • Clean. Works well. – Jake Feb 26 '18 at 15:37

0 Answers0