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 8703403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:34+00:00 2026-06-13T02:51:34+00:00

I am really struggling to structure the Sass files in a Rails 3.1 project

  • 0

I am really struggling to structure the Sass files in a Rails 3.1 project to avoid massive duplication …

I have the following structure, with application.css.scss being imported as part of my main layout:

application.css.scss
  - [*= require] main.css.scss
      - [@import] 'variables';
      - [@import]'bootstrap_overrides';
      - [@import]'bootstrap';
      - [@import]'base_elements';
      - [@import]'superstructure';
      - [@import]'modules';

So far so good. All these files are combined by sprockets into a single document. However I then want to modularise my Sass further, with page-specific files or files shared across regions of my site.

So on my GalleryResource#show page I need to use additional Sass files:

resource.scss
gallery_resource.scss
badges.scss

And maybe a css file from a lib:

gallery_lib.scss

These files need to reference a number of the files already imported in application.css. They need to make use of variables defined in variables.css.scss and of mixins defined in bootstrap. So I am forced to reimport these files in each file that uses them, causing massive duplication. I could write a manifest file for each and every page, but this is a maintenance nightmare and still results in duplication and two css files; application.css and page_specific.css.

So what is the solution? Do I need to dispence with application.css and move its imports into each page-specific file? So using the above example I would end up with a single manifest file that looks like this:

gallery_resource_manifest.css.scss
      - [*= require] gallery_lib.css
      - [*= require] gallery_resource.css.scss
         - [@import] 'variables';
         - [@import]'bootstrap_overrides';
         - [@import]'bootstrap';
         - [@import]'base_elements';
         - [@import]'superstructure';
         - [@import]'modules';
         - [@import]'resource';
         - [@import]'gallery_resource';
         - [@import]'gallery';
         - [@import]'badges';
  • 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-06-13T02:51:35+00:00Added an answer on June 13, 2026 at 2:51 am

    I solved this by taking a cue from rspec, and creating a _sass_helper.sass partial, which contains all my non-direct-style imports (variables, mixins, placeholders), which is then included at the top of each file. The non-code bit is important, because if _sass_helper.sass contained any styles, they would be written into each file.

    This effectively allows me to get the same “Sass environment” for each of my files, without any code duplication.

    I have my tree organized like so:

    includes/
      _variables.sass
      _mixins.sass
      _extends.sass
    posts/
      _post_partial_1.sass
      _post_partial_2.sass
    application.sass
    posts.sass
    _sass_helper.sass
    

    Then, something like posts.sass would look like:

    @import 'sass_helper'
    @import 'posts/post_partial_1'
    @import 'posts/post_partial_2'
    
    .some.globally.shared.post
      styles: here
    

    It works great. The post partials don’t need the sass helper, so I end up with one master file per controller, with partials for individual features, and the same environment everywhere.

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

Sidebar

Related Questions

im really struggling to find clear documentation on the following subject. I have created
I'm really struggling with require.js and jquery mobile. I have a loosely based file
I'm really struggling with this. I have a viewdetails.php page, addnew.php page and a
I'm currently struggling to understand how I should organize/structure a class which I have
Really like objectify, although still struggling with what is the best way to structure
Really struggling to work this out... I have a text file with data like
I'm really struggling with this. I have a flash demo built in AS2 (not
I'm really struggling with the following pinvoke call. I've tried numerous different ways of
Really struggling to understand this problem, any ideas are welcome I have a carousel
Im really struggling to get my head around what should be simple, I have

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.