addressing asset stylesheets with file extensions - ruby-on-rails

I have some stylesheets in a subfolder /app/assets/stylesheets/themes of my rails app. These assets have the file extension .css.scss extension.
In my development environment I've been addressing those files with:
asset_path 'themes/theme-name.css.scss'
However, when I go to production Rails won't find those files. When I use just .css extension it seems to be working okay:
asset_path 'theme/theme-name.css'
My question is: what is the correct way to address asset files with multiple extensions?
Thanks for help

The correct way should be:
stylesheet_link_tag 'themes/theme-name'
If Rails is configured correct, the assets pipeline will figure out the file extensions itself .

Do you have sass loaded in your Gemfile?

Related

After upgrading to new Rails version few images are broken

So my company updated Rails and Ruby versions, after that only few images became broken. They all defined in scss with image_url("frontend/image_title.png"), but only like 4 of them aren't showing anymore, server gives 404 error.
All of them used as a background images.
What could be a problem and a solution?
Have you tried precompiling the assets ?
The call too image_url is done once during precompilation of assets so it could be that the assets in production still have old paths.
To precompile run the following command:
bundle exec rake assets:precompile
Looks like i will always answer my own questions :)
The problem was that there are few .scss files that was compiling with assets pipeline, and those .scss files had some same code, like scss variables and reset code, which i decided to move out of them to separate file, called reset.css.scss and import that file into those .scss files with #import function, which works bad with Rails *= require methods.
After moving that code back to .scss files and removing the #import stuff, everything worked fine.

Including CSS files in PDF using wicked_pdf helpers

I am successfully loading CSS files in my PDF file using wicked_pdf gem helpers:
<%= wicked_pdf_stylesheet_link_tag "pdf" %>
This works great in development, however when i deploy in production the pdf CSS file is not correctly imported. Also note that the file is "pdf.scss.erb" and not just "pdf.css".
I am not sure how to fix this problem. Looking at the server logs, i do not see any missed file warnings.
I myself solved the problem by duplicating the styles right onto the layout page.
However at this github thread people are advising to do several things:
Include the files in your precompile list in config/initializers/assets.rb as described in the Asset pipeline usage section of the README.
Using stylesheet_link_tag wicked_pdf_asset_base64('pdf')
wkthmltopdf not bundling with dependency library to wkthmltopdf can install the gem after installed gem run bundle install
gem "wkhtmltopdf-binary"

Heroku does not load assets from asset pipeline

In my Rails app I have css and js that is unique to each action.
So users#new has its own css. It's named users_new.css.scss.
I deployed my app to Heroku, and Heroku isn't loading any of the assets. You can see the errors here. How do I fix this so Heroku correctly precompiles and loads the assets?
I read through Heroku's docs on using the asset pipeline, but didn't see any solution.
Precompilation
The problem is your timelines_index.js is not precompiled:
The way you can tell this is a problem is that when you call the asset in your layout (which I presume you're doing with the correct path helpers), Rails will automatically reference the latest precompiled version of that file (hence why application.js has the appended MD5 fingerprint)
I believe you'll need to add your custom files to your precompiled_assets array:
#config/environments/production.rb
Rails.application.config.assets.precompile += ['timelines_index.js']
This will give Rails the ability to precompile those assets individually, allowing you to call them in your layout:
#app/views/layouts/application.html.erb
<%= javascript_include_tag "timelines_index" %>
This will have to be done for all the custom asset files you wish to call in your layout.
Manifest
As mentioned by Anil, you may wish to use the manifest system of Rails to concatenate all your asset files into their respective application files.
This will quash the need to append the files to the Rails precompile array, allowing you to call a single file for your various assets:
#app/assets/javascripts/application.js
//= require_tree .
Add in your Gemfile
gem 'rails_12factor', group: :production

Why are wicked_pdf asset helpers generating errors on Heroku

I'm using wicked_pdf in a Rails 4.1 app.
PDF generation works perfectly within my local dev setup. But I get errors when deployed to Heroku.
Checking the logs I see
ActionView::Template::Error (No such file or directory - /app/public/photos/application.js):
associated with the wicked_pdf helpers
<%= wicked_pdf_javascript_include_tag "application" %>
I understood that the wicked_pdf helpers generated absolute urls, so
why am I seeing a relate url originating from the app folder?
How is this path being generated? I have no public/photos folder in
my app!
How do I go about debugging this problem? I'm unsure if this is a Heroku issue, a wkhtmltopdf issue, an asset compilation issue, or...?
Is anyone using wicked_pdf successfully on Heroku?
This is a new issue in Rails 4 (4.1?), where the compiled assets come out with digests like this:
application-4dd5b109ee3439da54f5bdfd78a80473.js
but no plain
application.js
is generated anymore.
You can try this gem https://github.com/alexspeller/non-stupid-digest-assets
or I would recommend base64 encoding your assets like described in this issue:
https://github.com/mileszs/wicked_pdf/issues/257
I'm working on rolling this into WickedPdf very soon, as this is a common issue to have differences in environments due to asset pipeline stuff.
I see that there is no an asets digest in log info that rails use for assets in producation environment.
I think the gem should resolve the issue because it was written for using wikedpdf on Heroku.
You can add it like that:
group :production do
gem "wkhtmltopdf-heroku"
end

How do I remove SASS from a rails project?

I have forked a rails project and found that is uses SASS, I want to remove SASS and write my css by hand.
Can i just delete the folder:public/stylesheets/sass? Remove the gem from the gemfiles, and then continue with the .css files that sass has generated?
Since there is already generated SASS, the method you suggest is the best. You do not want the SASS files overwriting your CSS.
The files with .css extension have no treated by gem sass, you can write your .css file think to change stylesheet_link_tag in layout for load your .css

Resources