newBike
newBike

Reputation: 15002

How to apply assets to different controller

I bought two themes from https://wrapbootstrap.com/

I put the first theme under assets/index_theme

So I added //= require_tree ../theme/js in .//assets/javascripts/application.js and add file .//app/assets/lenord-single-page-theme/js/application.js

.//app/assets/lenord-single-page-theme/js/application.js

//= require_tree .

and did the same thing for css.

But it applied to all pages in whole websites

I only want to apply it on a specific controller's view only for index

And Applied another theme to others controllers' views

How could I achieve it ?

.
├── images
├── javascripts
├── stylesheets
└── lenord-single-page-theme
    ├── css
    ├── fonts
    ├── img
    │   ├── portfolio
    │   ├── prettyPhoto
    │   │   ├── dark_rounded
    │   │   ├── dark_square
    │   │   ├── default
    │   │   ├── facebook
    │   │   ├── light_rounded
    │   │   └── light_square
    │   └── service
    ├── js
    └── rs-assets

Upvotes: 1

Views: 42

Answers (1)

Philip7899
Philip7899

Reputation: 4677

In your application.html.erb file:

<% if params[:controller] == 'your_controller_name' %>
      <%= stylesheet_link_tag 'index_theme.css' %>
< %end %>

If you need even more control and only want specific actions:

<% if params[:controller] == 'your_controller_name' && params[:action] == 'your_action_name' %>
      <%= stylesheet_link_tag 'index_theme.css' %>
< %end %>

If you are trying to conrol javascript files instead of css:

<% if params[:controller] == 'your_controller_name' && params[:action] == 'your_action_name' %>
      <%= javascript_include_tag "/assets/index_theme.js" %>
< %end %>

notice the js tag includes /assets/ and the css tag does not.

Upvotes: 1

Related Questions