1

I am new to ruby on rails and whenever i create and access a controller i can see it loads a new css & js file with name as the name of the controller...

How can i make it load only 1 css and js file called style.css and site.js for example?

what is the purpose of having multiple js & css files whenever i access a contrller?

if i go to application.html.erb and change

  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>

to

  <%= stylesheet_link_tag("application") %>
  <%= javascript_include_tag("application") %>

it doesnt seem to help

1
  • 1
    In development mode files never compiled for debug purposes. In production they are compiled. Commented Jun 21, 2012 at 11:31

3 Answers 3

2

I dont know which Rails version you are using, but assuming it is the recent one, then Rails are using Assets Pipeline, to merge multiple files and serve all css / javascript files compressed / merged.

You can learn more about it at http://guides.rubyonrails.org/asset_pipeline.html

Basically what you do is, you reference one file 'application' (css or js) and inside this file, you customize which files it should include.

Sign up to request clarification or add additional context in comments.

Comments

1

The code:

<%= stylesheet_link_tag    "application", :media => "all" %>
<%= javascript_include_tag "application" %>

will include all .css and .js files available in assets/javascripts/ and assets/stylesheets/. So, if you want to include only the style.css and site.js just remove everything else.

Your assets/javascripts/ should have only the application.js and site.js.

And your assets/stylesheets/ should have the application.css and style.css.

EDIT

`application.js and application.css are part of the asset pipeline.

You can disable it if you want by adding this line in your application.rb

config.assets.enabled = false

You can also change the application.html.erb to include only your style.css and site.js:

<%= stylesheet_link_tag    "style", :media => "all" %>
<%= javascript_include_tag "site" %>

I hope it helps...

2 Comments

whats the difference on those 2 js files and css files? can i have only site.css and site.js? or its required to have both?
It is recommended to have both: "You should use the defaults for all new applications unless you have a specific reason to avoid the asset pipeline" (Rails Guide), but I have edited my answer to you :)
0

Try using :cache => 'cache-display'

<%= stylesheet_link_tag :all, :cache => 'cache/display' %>
<%= javascript_include_tag :all, :cache => 'cache/display' %>

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.