Sass with erb won't compile
This is indeed a problem with sass-rails
, as discussed on GitHub.
So this guy wrote this patch, which completely solves the problem.
The Solution
Add to Gemfile
:
gem "sass_rails_patch", "~> 0.0.1"
then run bundle
and you're good!
assets:precompile tries to compile a sass partial when it shouldn't
The file names/patterns in the list of things to precompile do not refer to the filenames of things to precompile. Instead they refer to the results of precompilation i.e. asking for '*.css' to be precompiled means precompile anything that if compiled would result in a .css file. In particular, a .css.sass file like your _account file will be precompiled.
Assets not being run though the .erb preprocessor
Ruby documentation seems a bit unclear on a few things such as the usage of the asset_path
and other such helper in stylesheets. Anyways this is what I did to get around the exact same problem:
I decided to do this the SASS-way by changing my stylesheet extensions from css to scss.
The image references in my code were changed frombackground-image: url(<%= asset_path 'blah.png' %>);
tobackground-image: image-url("blah.png");
I've also added the config.assets.digest = true
line to my config/appliction.rb
file because that seemed to get my output HTML to refer to the hashed filenames. Without the digest
flag set to true I get all of my link tags starting off with <link href="/assets/print.css?body=1" ...
or <href="/assets/favicon.png"...
which pretty much defies the purpose of using the assets pipeline. Especially the favicon file will still be cached by the servers and CDN's along the way.
Explicitely setting the digest flag to true gets me <link href="/assets/print-e47f5a48af04ce6854c840d74cd28fba.css?body=1"
and <link href="/assets/favicon-15fb5e00d868940bc32db7996e10f594.png" ...
Rails erb preprocessing not happening in development mode
The scss needs quotes around the 15px part. So you will need to make it:
$headerHeight: "<%= '15px' %>";
Can we use scss (sass-rails) in rails css.erb view files or is this just a asset pipeline thing?
Its theoretically possible by invoking the sass compiler. Note that you want to be using a request for css and not scss. There is no reason the client needs to know how the file is produced.
<%= stylesheet_link_tag(about_me_user_path(current_user, format: :css), media: 'all', class: "home_about_me_css") %>
class UsersController
def user_profile_stylesheet
respond_to do |f|
f.css do
fn = Rails.root.join('app', 'views', 'home', 'home_stylesheet.css.scss.erb')
# expand ERB template
sass = render_to_string(file: fn)
# run rendered template through the sass compiler
css = SassC::Engine.new(sass, style: :compressed).render
render text: css
end
end
end
end
I'm not so sure its something you really want to do in production as it requires you to compile sass at run-time when responding to requests. And you won't be able reference anything like SASS functions in your assets pipeline since this is compiled outside the pipeline.
Its also a security nightmare since SASS is not just declarative like CSS. And this could be exploited to execute code on your server.
Whatever you're trying to do there has to be a smarter / less complex solution.
CSS in Rails Asset Path not processed by ERB in development
I was using Rails 3.1.1 and when I switched the app to use Rails 3.1.3, the problem went away. I switched back to 3.1.1 to see if the issue came back and it did not.
I'm guessing that it was a problem with one of the gems and the update to 3.1.3 brought other gem updates with it.
Compiling Sass with custom variables per request under Rails 3.1
Sim.
It is possible. Look here SASS: Set variable at compile time
I wrote a solution to address it, I'll post soon and push it here, in case you or someone else still need it.
CSS / SCSS won't update in ruby on rails running in Docker
Hi it seems that deleting the assets
folder in the public/assets
directory solved this issue. And also in my Application.js
I've changed the turbolinks from //= require jquery.turbolinks
to //= require turbolinks
. Don't know how it explains this but this solved the issue I did added the gem into my Gemfile gem 'turbolinks', '~> 5.2.0'
may because of some deprecated gems that I've used.
Using erb within scss to render an model field
Unless you have your asset's pipeline turned off and just compile the scss sources with each request, this won't work, it will work once and then whenever you change that image, you'd have to recompile the sass file again for the change to take effect.
I'd move this functionality to inline css within the views; the asset pipeline is meant for the rarely dynamic content hence its precompiled and no processing happens beyond that during runtime.
Related Topics
How to Use Gems Not in a Gemfile When Working with Bundler
Net::Ssh Sudo Command Hangs After Entering Password
Check If an Array Is Subset of Another Array in Ruby
What Does "<Top (Required)>" Mean in a Ruby Stack Trace
Why Can't I Use an Integer as a Key Using the New Ruby 1.9.2 Hash Syntax
Add Space After Commas Only If It Doesn't Already
How to Run a Single Test/Spec File in Rspec
How to Implement Cookie Support in Ruby Net/Http
Convert a String to Regular Expression Ruby
How to Skip Has_Secure_Password Validations
Does Ruby Call Initialize Method Automatically
Sort a Collection of Objects by Number (Highest First) Then by Letter (Alphabetical)
Yaml Indentation for Array in Hash
How to Escape #{ from String Interpolation