Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6092499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:26:58+00:00 2026-05-23T12:26:58+00:00

How can I include specific JS or CSS files (by convention ?) with Ruby

  • 0

How can I include specific JS or CSS files (by convention ?) with Ruby Rails 3.1 ?

I have a view :
views/project/index.html.erb

And I want to include a specific javascript file for this page. I put it in
assets/javascripts/project/index.js

Same for another view :
home/index.html

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:26:58+00:00Added an answer on May 23, 2026 at 12:26 pm

    In the application.css and application.js file, be sure to remove the line \\= require tree.

    Then, manually list all the css/js files you want included in each manifest file, for example:

    // application.js
    //= global.js
    //= everywhere.js
    

    Then, I would setup a yield in your header or your closing body tag for your application layout file, for instance (in haml)

    %head
      %title Some Page
      = stylesheet_link_tag 'application'
      = yield :stylesheets
    

    Then in your particular view, say _example_partial.html.haml, do this:

    - content_for :stylesheets do
      = stylesheet_link_tag 'example_partial'
    
    -# the rest of your view goes here
    

    You do the exact same thing with Javascript files, just using javascript_include_tag instead of stylesheet_link_tag.

    This will let you quickly and easily assemble view-specific javascript / css payloads. There may be a more sophisticated way to handle this using the asset pipeline, but I would suggest that if the asset pipeline is already minifying and merging you major stylesheets that this kind of +1 css / js file per view is not going to cause a major performance hit. Just try to make sure you don’t overdo it with dozens of separate files loading into a single view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can include .asp file inside of html file and have it proccessed besides
Given a view with layout, how can I load static files (CSS and JS,
I'm trying to include specific 'admin view' files from within a folder structure. I'm
What would be the CSS conditional statement you can use to include specific CSS
I have certain page-specific js and css files that I either: Don't want running
I have a specific problem regarding my website that I built with HTML, CSS,
Here is what I have- How I can include multiple keys and their values
I have a loooooooooooong SELECT ending with a ORDER BY that can include the
I have several textboxes where users can enter information into them. This can include
In my CodeIgniter application have a common header and footer view, which I include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.