Rails Puma: --no-dev-caching does not work - ruby-on-rails

Whenever I change an included .scss file I cannot see the changes, even if I restart the server. I found that if I manually delete tmp/cache/* then restart the server, I can see the changes one time. Further changes are not shown (and the cache is back). I have tried rails server --no-dev-caching but it doesn't help. I have
config.assets.digest = false
config.assets.debug = false
config.assets.quiet = false
config.assets.raise_runtime_errors = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
How can I see changes to my SCSS files when I reload the page in development? I test with curl http://localhost:3000/assets/application.css | less and search for the class that I changed and saved.
=> Booting Puma
=> Rails 5.0.7.2 application starting in development on http://localhost:3000
* Version 3.12.2 (ruby 2.4.3-p205), codename: Llamas in Pajamas
* Environment: development
Docs: https://guides.rubyonrails.org/v5.0/configuring.html#configuring-assets
I commented out Puma, used WebBrick with rails server --no-dev-caching, set config.assets.debug = true, loaded $ curl http://localhost:3000/assets/theme/theme.self.css | less, and the change was still not there.

I found the answer here! https://stackoverflow.com/a/59895954/148844
I had to change #import "theme-overrides.scss"; => #import "theme-overrides";, rename theme-overrides.scss => _theme-overrides.scss, change #import "theme_components/helpers.scss"; => #import "theme_components/helpers";, rename helpers.scss => _helpers.scss, and it all worked!
Now I have to rename 100 different files!

Related

Upgrade redis from v2 to v4 on Windows causes Rails connection error

Background
My dev environment is Windows, Rails cache_store worked fine for redis V2.
I am implementing ActiveJob with sidekiq, which required redis >= v3
I installed Redis for Windows from GitHub, I tried both V4 and V5.
Windows setup
Ran the installation .msi file
After install and re-boot, checked the redis-cli and connected and tested fine.
Rail setup
from config/environments/development.rb
config.cache_store = :redis_cache_store, { url: 'redis://localhost:6379/0' }
Rails console
>> Rails.cache
=> #<ActiveSupport::Cache::RedisCacheStore options={:namespace=>nil, :compress=>true, :compress_threshold=>1024, :expires_in=>nil, :race_condition_ttl=>nil} redis=#<Redis client v4.2.5 for redis://localhost:6379/0>>
>> Rails.cache.redis.connected?
=> false
>> t = Rails.cache.fetch('test') { 'T' }
=> "T"
>> r = Redis.new
=> #<Redis client v4.2.5 for redis://127.0.0.1:6379/0>
>> r.get 'test'
=> "123"
>> r.connected?
=> true
Question
What am I doing wrong in my config?
Solved!
Changed development.rb to:
config.cache_store = :redis_cache_store, { url: 'redis://127.0.0.1:6379/0' }

Rails low level cache not working in development mode

I've configured the development.rb file like this:
# Enable/disable caching. By default caching is disabled.
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
(erased the default config that checks for a file just to test)
Then I open a rails console to test this but it does not seem to be working:
[1] pry(main)> Rails.cache.write("asd", "asd")
=> true
[2] pry(main)> Rails.cache.read("asd")
=> nil
I've managed to make it work a couple of days ago, but now it is not working.
A I missing something?
I fixed it by restarting spring. Doing
> spring stop
Spring stopped.
> spring start
does the trick.
Note: when starting spring again, it may fail, but it'll work anyway.
In rails 6.1.4
run rails dev:cache to toggle caching in development

jpegrecompress worker: `jpeg-recompress` not found;

I recently installed the paperclip-optimizer gem in my Rails 4 app on Heroku. Whenever I attempt to save an uploaded image attachment, I get the following error: jpegrecompress worker: 'jpeg-recompress' not found; in my logs from Heroku, but not on localhost.
I'm not sure what I'm missing. I can't seem to find a single StackOverflow post, blog post, or other resource on this problem.
Here is my config/initializers/paperclip_optimizer.rb:
Paperclip::PaperclipOptimizer.default_options = {
skip_missing_workers: true,
advpng: false,
gifsicle: false,
jhead: false,
jpegoptim: false,
jpegrecompress: true,
jpegtran: false,
optipng: false,
pngcrush: false,
pngout: false,
pngquant: true,
svgo: false,
nice: 10, # Nice level (defaults to 10)
threads: 1, # Number of threads or disable (defaults to number of processors)
verbose: false, # Verbose output (defaults to false)
pack: nil, # Require image_optim_pack or disable it, by default image_optim_pack will be used if available,
allow_lossy: true, # Allow lossy workers and optimizations (defaults to false)
jpegrecompress: {
quality: 2 # JPEG quality preset: 0 - low, 1 - medium, 2 - high, 3 - veryhigh (defaults to 3)
},
pngquant: {
quality: 100..100, # min..max - don't save below min, use less colors below max (both in range 0..100; in yaml - !ruby/range 0..100) (defaults to 100..100)
speed: 3 # speed/quality trade-off: 1 - slow, 3 - default, 11 - fast & rough (defaults to 3)
}
}
In my photo.rb model I have:
has_attached_file :image, styles: { large: "600x600>", medium: "300x300>", thumb: "100x100>" }, default_url: "", processors: [:thumbnail, :paperclip_optimizer]
In my .buildpacks file for Heroku I have:
https://github.com/ddollar/heroku-buildpack-multi.git
https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/bobbus/image-optim-buildpack.git
I added the Ruby buildpack to solve this problem I was having earlier, but now it seems as though the multi and the image-optim buildpacks aren't loading.
Thanks!
After much head banging and keyboard bashing, I figured out how to solve the problem. In my case, I'm running a Rails 4.0 app on the Cedar-14 stack running on the Puma webserver, so these instructions may or may not be of use to you if you're configuration is different.
I followed the steps on this Heroku Dev Center article on adding multiple buildpacks to an app, which is now supported by Heroku.
In my case, I have the following buildpacks added for my app:
=== staging-app Buildpack URLs
1. https://github.com/bobbus/image-optim-buildpack.git
2. https://github.com/heroku/heroku-buildpack-ruby.git
The order is critical. The last buildpack on the list is the first one to be loaded. In my case, I need the Ruby buildpack so that the bundle command in my Procfile is recognized. See this question for more on that issue.
Do NOT use the Heroku-Buildpack-Multi. From what I understand, this is the old way to support multiple buildpacks. Adding this will cause your pushes to be rejected.
In my Gemfile, I needed to include the image_optim and image_optim_pack gems. These gems make the appropriate binaries available on OS X and Linux environments, from what I understand. It is very important to place these gems before paperclip-optimizer in the Gemfile, like so
gem 'paperclip', '~> 4.1'
group :production do
# Needs to be placed before paperclip-optimizer
gem 'image_optim'
gem 'image_optim_pack'
end
gem 'paperclip-optimizer'
Configure your paperclip-optimizer settings as you see fit and push to production.
Hopefully this helps someone in my situation.

Bootstrap glyphicons error 404 in production

I'm using bootstrap-sass-rails this issue and when I run my rails project in production mode I get 3x 404 errors:
GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.woff 404 (Not Found) assets/twitter/bootstrap/glyphicons-halflings-regular.woff:1
GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.ttf 404 (Not Found) assets/twitter/bootstrap/glyphicons-halflings-regular.ttf:1
GET http://localhost:3000/assets/twitter/bootstrap/glyphicons-halflings-regular.svg 404 (Not Found)
I used rake assets:precompile RAILS_ENV=production to generate static files with result :
I, [2013-11-07T16:52:25.269370 #12948] INFO -- : Writing myproject/public/assets/application-3517eb39b597107b3dbccbcbf4f0b3cc.js
I, [2013-11-07T16:52:25.315358 #12948] INFO -- : Writing myproject/public/assets/application-1459bfe79a6477170658d53257e4a8fd.css
I, [2013-11-07T16:52:25.334356 #12948] INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-8b1bdc16b9e098d67afebbf8d59fcea7.eot
I, [2013-11-07T16:52:25.345360 #12948] INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-8d8305e5b6a807076d3ec68e2f190674.svg
I, [2013-11-07T16:52:25.357360 #12948] INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-946071b70245967633bb3a774c60f3a3.ttf
I, [2013-11-07T16:52:25.367360 #12948] INFO -- : Writing myproject/public/assets/twitter/bootstrap/glyphicons-halflings-regular-d7e2274ad1d940a0b2ce7480810ab223.woff
etc ...
All assets are working fine except these 3 font files. I searched all day long and didn't find anything. It seems rails is looking for the version without hash of these 3 files but rake generates them with hash
my config/production.rb :
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
EDIT
I tried to override the #font-face variable but it doesn't seem to remove old variables:
#font-face {
font-family: 'Glyphicons Halflings';
src: asset-url('twitter/bootstrap/glyphicons-halflings-regular.eot',font);
src: asset-url('twitter/bootstrap/glyphicons-halflings-regular.eot?#iefix',font) format('embedded-opentype'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.woff',font) format('woff'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.ttf',font) format('truetype'), asset-url('twitter/bootstrap/glyphicons-halflings-regular.svg#glyphicons-halflingsregular',font) format('svg');
}
I now have glyphicons loaded but still 3x 404 errors.
Ok then.
I switched to https://github.com/thomas-mcdonald/bootstrap-sass .
Pretty same bootstrap version and no problem with it.
EDIT UPDATE
bootstrap-sass has been updated. You need to make some changes as explained on github page if you still have 404 errors.
I had the same problem. It turned out that I had to add #import "bootstrap-sprockets" in addition to #import "bootstrap" inside application.css.sass.
ADD MIME TYPE into your webserver.
You have to define how to provide woff file.
for IIS, go to your IIS and open MINE type window
click ADD and type "woff" for first input box
and "application/x-font-woff" for second box
then repeat for other extensions
good luck
the font directory is not automatically seen as a asset directory. You need to add it explicitly by setting: config.assets.paths << Rails.root.join("app", "assets", "fonts") in the application.rb file.

Thinking Sphinx min_inflex_len and delta not working on production server

We have an issue with TS min_inflex_len and delta indexes on our production servers
I have everything working in development mode on OSX but when we deploy via capistrano to our Ubuntu server running passenger / apache, both delta indexing seems to stop as well as min_inflex_len
We're deploying as ubuntu user which also runs apache. We had an issue yesterday with production folder not being created but we manually created and I can see a list of the delta files in there now.
I've followed the docs through..
I can see the delta flag set to true on record creation but when searching it doesn't find the record. Once we rebuild index (as ubuntu user) I can find record, but only with full string.
My sphinx.conf file is as follows:
production:
enable_star: 1
min_infix_len: 3
bin_path: "/usr/local/bin"
version: 2.0.5
mem_limit: 128M
searchd_log_file: "/var/log/searchd.log"
development:
min_infix_len: 3
bin_path: "/usr/local/bin"
version: 2.0.5
mem_limit: 128M
Rebuild, start and conf work fine and my production.conf file contains this:
index company_core
{
source = company_core_0
path = /var/www/html/ordering-main/releases/20110831095808/db/sphinx/production/company_core
charset_type = utf-8
min_infix_len = 1
enable_star = 1
}
I also have this in my production.rb env file:
ThinkingSphinx.deltas_enabled = true
ThinkingSphinx.updates_enabled = true
My searchd.log file only has this in:
[Wed Aug 31 09:40:04.437 2011] [ 5485] accepting connections
Nothing at all appears in apache error / access log
-- EDIT ---
define_index do
indexes :name
has created_at, updated_at
set_property :delta => true
end
Not sure if it's the cause, but the version values in your sphinx.yml are for the version of Sphinx, not Thinking Sphinx - so you may want to run indexer to double-check what that value should be (likely one of 0.9.9, 1.10-beta or 2.0.1-beta).
Also: on the server, in script/console production, can you share the full output of the following (not interested in the value returned, hence why I'm forcing it to be an empty string - it'll just get in the way otherwise):
Company.define_indexes && Company.index_delta; ''
``
delta not working on production server for passenger user, you have to give the write permission to your passenger user when creating index and write it to db/sphinx/production folder.
Or you can set two line in your nginx/conf/nginx.conf
passenger_user_switching off;
passenger_default_user root;
Example:
passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.0;
passenger_ruby /usr/local/bin/ruby;
passenger_user_switching off;
passenger_default_user root;

Resources