Sprocket and Rails 3.1: Load different files depending on which controller is loaded
-
26-10-2019 - |
Question
I have been looking over the web for this but I can't seem to find documentation for what I'm looking for.
I have a rails application and depending on which controller is used, I want to serve different css/js files.
Right now, I can either load EVERY file or only application.(css|js)
Solution
I solved this issue after a good night of sleep. Here's the solution:
application.html.erb
<html>
<head>
<%= stylesheet_link_tag "application", controller_name, "template"%>
<%= javascript_include_tag "application" , controller_name %>
</head>
</html>
controller.js.coffee
//= require ender
controller.css.scss
//= require sub-template
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow