3

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.

1
  • You can create a different layout for that specific controller, then do not include the css and js file on that layout. Commented Aug 11, 2016 at 3:59

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.