Ceejay
Ceejay

Reputation: 7267

How can i include only custom css and js files in rails application

Here i am trying to include my custom js and css files in my rails application. i am a newbie to rails.. right now my application is linked to all the js and css files that i have in assets directory...

but i don't need them. i need to add only my js files.... how can i add it in to my rails application.... can i add it through layout file?

here is my layout file

<!DOCTYPE html>
<html>
<head>
  <title>Walden</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>  
  <%= csrf_meta_tags %>
</head>
<body>
<%= render 'shared/navbar' %>
<%= yield %>
</body>
</html>

right now it is linked to all css and js files like this.

<link data-turbolinks-track="true" href="/assets/user_details.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/affix.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/alert.js?body=1"></script>

example: i need to add only juery.js file and user_details.css file...how to add it?

Upvotes: 1

Views: 171

Answers (1)

Brad Werth
Brad Werth

Reputation: 17647

Well, you have two basic choices:

Remove the extraneous files from your application.js and application.css.

or

<%= stylesheet_link_tag    'user_details', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'jquery', 'data-turbolinks-track' => true %>

http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_include_tag

http://apidock.com/rails/v4.2.1/ActionView/Helpers/AssetTagHelper/stylesheet_link_tag

Upvotes: 1

Related Questions