How can i prevent one of my Rails app Controller from loading the general css and js that is loaded on the whole app ?
Thanks for reading.
Option 1
If page should be without any layout (which includes css and js), you can do something like this:
class MyAwesomeController < ApplicationController
layout false
end
Option 2
If you need some layout, but without any css and js, create it in views/layouts. For example no_css_and_js.html.erb. Then add html without any css and js including:
<!-- layouts/no_css_and_js.html.erb -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<%= yield %>
</body>
</html>
Then your controller should be modified to use this layout:
class MyAwesomeController < ApplicationController
layout 'no_css_and_js'
end
Option 3
Also you can modify your application layout to prevent it to load css and js:
<!DOCTYPE html>
<html>
<head>
<title>Orca</title>
<% if controller_name != 'my_awesome' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<% end %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
layoutfor that specific controller, then do not include the css and js file on that layout.