Ruby on Rails, image compilation and precompilation - ruby-on-rails

I just deployed a rails app and I am having an error when I load a page saying:
We're sorry, but something went wrong.
In the production.log I see that message:
Started GET "/" for 128.179.252.130 at 2014-11-30 08:32:28 +0000
Processing by StaticPagesController#home as HTML
Rendered static_pages/home.html.erb within layouts/application (0.4ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_header.html.erb (2.4ms)
Completed 500 Internal Server Error in 4ms
ActionView::Template::Error (./icons/icon_nameplate.png isn't precompiled):
37:<ul class="dropdown-menu">
38:
39:<li>
40: <%= menu_dropdown('Profile', "./icons/icon_nameplate.png", "Nameplate Icon", current_user) %>
41:</li>
So I believe the error comes from this part of the message:
./icons/icon_nameplate.png isn't precompiled
I searched the internet, found three possible solution, none of which did work:
1. config.assets.compile = true (in production.rb file)
2. config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] (still in production.rb file)
3. bundle exec rake assets:precompile RAILS_ENV=production
All of this changed absolutely nothing, and the website still shows the same error. So I am turning for you to help.
Thank you very much in advance.

What finally did the trick for me is completely restart the rails app. This is described in the link below.
The recommended version did the trick for me which is:
Create (or update) a file called restart.txt in the tmp folder of your Rails application on the server.
After that no problem at all.
Cheers

Related

Rails redirect loop in production, everything is fine in development

I am running into an issue with Rails where in production it generates an error in the log file, but nothing in the development mode:
I, [2019-10-16T12:02:16.953954 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Started GET "/" for 155.186.157.103 at 2019-10-16 12:02:16 -0500
I, [2019-10-16T12:02:16.955549 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Processing by Devise::SessionsController#new as HTML
I, [2019-10-16T12:02:16.956733 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Rendering devise/sessions/new.html.erb within layouts/application
I, [2019-10-16T12:02:16.958443 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Rendered devise/shared/_links.html.erb (0.3ms)
I, [2019-10-16T12:02:16.958796 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Rendered devise/sessions/new.html.erb within layouts/application (2.0ms)
E, [2019-10-16T12:02:29.471353 #11866] ERROR -- : [2c2037b2-3b07-495d-b936-778c070e1ad7] undefined method `[]' for nil:NilClass
I, [2019-10-16T12:02:29.473147 #11866] INFO -- : [2c2037b2-3b07-495d-b936-778c070e1ad7] Redirected to [redacted-for-stackoverflow]
I, [2019-10-16T12:02:29.473928 #11866] INFO -- : [2c2037b2-3b07-495d-b936-778c070e1ad7] Completed 302 Found in 22438ms (ActiveRecord: 0.0ms)
E, [2019-10-16T12:02:39.225917 #11866] ERROR -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] undefined method `[]' for nil:NilClass
I, [2019-10-16T12:02:39.227867 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Redirected to [redacted-for-stackoverflow]
I, [2019-10-16T12:02:39.229075 #11866] INFO -- : [e5d5e3b6-2a9c-4d27-b1f3-2d5a1b76ce5a] Completed 302 Found in 22273ms (ActiveRecord: 0.0ms)
However, if I load development mode, the login page comes up just fine. I can't figure out what could possibly be causing this error since the error isn't descriptive as to where the issue resides.
I ran across another post to temporarily change config.consider_all_requests_local = false to config.consider_all_requests_local = true in config/environments/production.rb but that hasn't changed anything. No additional information is being provided.
How can I trace down this issue that's only occurring in production?
I have literally replaced everything in layouts/application.html.erb to try pin pointing where the issue is, but no luck. I noticed that rake assets:precompile fails as well with the same error, so perhaps it has some kind of issue in there.
Can you show the contents of devise/sessions/new.html.erb
It seems you are attempting to access a hash by key e.g. my_hash[:my_key] but my_hash in nil
After troubleshooting this some more, it finally boiled down to a stylesheet ending in .css rather than .css.scss since it was loading some rails stuff. I only came across this because rake assets:precompile kept failing.

webpacker compiling but not saving file in dev

I am working on a project using rails and react Am using webpacker. I get this message:
Processing by CurrenciesController#index as HTML
Rendering currencies/index.html.erb within layouts/application
[Webpacker] Compiling…
[Webpacker] Compiled all packs in C:/Users/omokehinde/Documents/RailsProjects/cryptoCalculator/public/packs
Rendered currencies/index.html.erb within layouts/application (9526.0ms)
Completed 500 Internal Server Error in 9955ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (Webpacker can't find hello_react.js in C:/Users/omokehinde/Documents/RailsProjects/cryptoCalculator/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the webpack -w or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
1: <%= javascript_pack_tag 'hello_react' %>
app/views/currencies/index.html.erb:1:in `_app_views_currencies_index_html_erb___1553736711_70532840'
the compiled file isn't saving and the packs folder isnt created.
here is a link to the repo on github: https://github.com/omokehinde/cryptoCalculator
please help!

Rails: Assets cannot be found in production mode, although being served properly by caddy

I have been trying to fix this problem for almost days now.
I am trying to run my ruby on rails site in production mode, but (some of) the assets cannot be served. The images are located in a custom subfolder ( app/assets/audio/testfolder/demo.png ) which is added to Rails.application.config.assets.paths and precompiled properly but I am always getting the error
ActionView::Template::Error (The asset "demo.png" is not present in the asset pipeline.)
or to be more specific:
I, [2017-09-25T00:38:32.859541 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Started GET "/" for 127.0.0.1 at 2017-09-25 00:38:32 +0200
I, [2017-09-25T00:38:32.860377 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Processing by TestControllerController#index as HTML
I, [2017-09-25T00:38:32.861240 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Rendering test_controller/index.html.erb within layouts/application
I, [2017-09-25T00:38:32.861558 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Rendered test_controller/index.html.erb within layouts/application (0.1ms)
I, [2017-09-25T00:38:32.863790 #41037] INFO -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] Completed 500 Internal Server Error in 3ms
F, [2017-09-25T00:38:32.864505 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1]
F, [2017-09-25T00:38:32.864789 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] ActionView::Template::Error (The asset "demo.png" is not present in the asset pipeline.):
F, [2017-09-25T00:38:32.865058 #41037] FATAL -- : [dd7b2824-614f-4e55-ba32-83548f79b2e1] 10:
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 11: <body>
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 12: <%= yield %>
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 13: <%= image_tag(yield(:img)) %>
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 14: <audio src="<%= audio_path(yield(:audio))%>" type="audio/mpeg" controls preload="none"></audio>
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 15: </body>
[dd7b2824-614f-4e55-ba32-83548f79b2e1] 16: </html>
The image can be accessed by localhost:81/assets/demo-57cec01fc3b0b102085dc4de14576f8fd86f8298aed121ce17245df0546276d4.png directly, so the webserver (caddy) does not seem to be the problem.
I hosted a simple demo project on github ( https://github.com/Kafkalasch/RailsAssetsErrorDemo ) to reproduce the problem easily.
Just clone the project, precompile the assets
rails assets:precompile
, start the caddy server with the given Caddyfile,
caddy -conf Caddyfile
and start puma with config/puma.production.rb
puma -C RubyDemo/config/puma.production.rb
I am using:
ruby 2.4.1
puma 3.10.0
rails 5.1.4
caddy 0.10.6
I could reproduce this problem on Debian and Mac OS X, so I don't assume that the OS is relevant.
I want to use my webserver to serve static files, so I am looking for an other solution than simply setting
config.assets.compile = true
Does anyone have an idea or any hint how I could solve my problem?
I am grateful for any response.
I tested your app with puma webserver in production and development.
I solved the error by including the folder for the mp3 and png files in your index.html.erb file.
<% provide(:img, "testfolder/demo.png") %>
<% provide(:audio, "testfolder/demo.mp3") %>
because your images and assets are precompiled inside public/assets/testfolder instead of public/assets
The problem is solved

Rails 3.1rc4 asset pipeline broke after Ruby update? How to re-activate/configure it?

Somehow this is related but I'm not sure how/why?
Just upgraded from Ruby 1.9.2-p180 to 1.9.2-p290 via RVM's rvm upgrade command...and now my asset pipeline is 'broken'.
During rvm upgrade ... I noticed a bunch of errors for each gemset along lines of:
ERROR: Error running 'rvm gemset pristine' under ,
please read /Users/meltemi/.rvm/log//gemset.pristine.log
I let upgrade continue as there was not much interesting in the gemset.pristine.log... besides, /Users/meltemi/.rvm/log//gemset.pristine.log doesn't (can't?) exist in that exact path? two consecutive '//' in a pathname? Anyway...
Testing a small app and though it launches and appears to run it is not loading any assets (images, css, etc.). Development log has many Not Found errors (see below) about these missing assets even though they exist within app/assets/images and app/assets/stylesheets, etc... ?
Anyone know what's happening here? Seems like pipeline has broken down somehow... As if Rails no longer knows to look for assets in app/assets, perhaps? How can I test/verify/fix/re-activate this 'pipeline'?
$ rails s
=> Booting WEBrick
=> Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-07-25 23:11:38] INFO WEBrick 1.3.1
[2011-07-25 23:11:38] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-07-25 23:11:38] INFO WEBrick::HTTPServer#start: pid=74881 port=3000
Started GET "/" for 127.0.0.1 at 2011-07-25 23:11:43 -0700
Processing by PostsController#index as HTML
Post Load (0.2ms) SELECT "posts".* FROM "posts" ORDER BY posts.created_at DESC
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Photo Load (0.3ms) SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 6
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 5
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 4
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 2
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Photo Load (0.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."post_id" = 1
Rendered posts/index.html.haml within layouts/application (3016.4ms)
Rendered layouts/_header.html.haml (9.7ms)
Completed 200 OK in 3143ms (Views: 3138.2ms | ActiveRecord: 2.9ms)
Started GET "/assets/application.css" for 127.0.0.1 at 2011-07-25 23:11:47 -0700
Served asset /application.css - 404 Not Found (1ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.css"):
Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290#rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2011-07-25 23:11:47 -0700
Served asset /application.js - 404 Not Found (0ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.js"):
Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290#rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)
Started GET "/assets/racer-outline.png" for 127.0.0.1 at 2011-07-25 23:11:48 -0700
Served asset /racer-outline.png - 404 Not Found (0ms)
ActionController::RoutingError (No route matches [GET] "/assets/racer-outline.png"):
Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290#rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (3.2ms)
Started GET "/assets/ray.png" for 127.0.0.1 at 2011-07-25 23:11:48 -0700
Served asset /pogo.png - 404 Not Found (0ms)
ActionController::RoutingError (No route matches [GET] "/assets/ray.png"):
Rendered /Users/meltemi/.rvm/gems/ruby-1.9.2-p290#rails3/gems/actionpack-3.1.0.rc4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
It seems that version 2.0.0.beta.11 of sprockets broke the assets pipeline. Putting
gem 'sprockets', '= 2.0.0.beta.10'
into your Gemfile seems to fix the problem (it worked for me). Rails seems to automatically use the most recent version of the beta for whatever reason so if you just started your project recently or updated all your gems it probably broke it.
Note that this info isn't mine originally, I got the fix from http://groups.google.com/group/rubyonrails-core/browse_thread/thread/59d8c7813b4d1bbe?pli=1
He explains the problem for ver. 2.0.0.beta.11 but I was using ver. 2.0.0.beta.12 with the same results so it seems that they haven't fixed it yet.
EDIT: It seems that upgrading your rails to 3.1.rc5 also fixes the problem
I ended up just blowing out the whole problematic gemset and starting anew. Lesson learned:
Don't trust rvm upgrade. Install the new Ruby w/in RVM. Then manually rebuild (or bundle install) your gemsets.

Heroku: see params and sql activity in logs?

When i view my heroku logs on the server (with heroku logs --tail --app myapp) i see something like this:
2011-06-21T14:09:25+00:00 app[web.1]: Started PUT "/reports/19.xml" for 77.89.149.137 at 2011-06-21 07:09:25 -0700
2011-06-21T14:09:25+00:00 heroku[router]: PUT myapp.heroku.com/reports/19.xml dyno=web.1 queue=0 wait=0ms service=7ms status=401 bytes=28
2011-06-21T14:09:26+00:00 heroku[nginx]: PUT /reports/19.xml HTTP/1.1 | 77.89.149.137 | 656 | http | 401
While in my local log i'd see something like this:
Started PUT "/reports/19" for 127.0.0.1 at 2011-06-21 15:27:01 +0100
Processing by ReportsController#update as XML
Parameters: {"report"=>{"workflow_status"=>"3"}, "id"=>"19"}
Person Load (0.9ms) SELECT "people".* FROM "people" WHERE "people"."email" = 'madeupemai#lkklj.com' LIMIT 1
Report Load (0.4ms) SELECT "reports".* FROM "reports" WHERE "reports"."id" = 19 LIMIT 1
DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from update_report at /home/max/work/rails_apps/flamingo_container/flamingo/vendor/plugins/resource_this/lib/resource_this.rb:135)
Creating scope :open. Overwriting existing method Task.open.
Task Load (2.0ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = 14 LIMIT 1
Completed 200 OK in 1648ms (Views: 568.2ms | ActiveRecord: 3.2ms)
Ie with a lot more information, particularly the params, info from the router, generated sql, any templates rendered etc etc.
Does anyone know how i can get my heroku log to be as verbose as my development one? I've done the following already:
1) Set the log level in the relevant (rails 3) environment file:
config.log_level = :debug
2) Told heroku to use a different logger level, as described on http://devcenter.heroku.com/articles/logging
heroku config:add LOG_LEVEL=DEBUG --app myapp #from CLI
Neither has made any difference...any ideas anyone?
thanks, max
You're essentially wanting to show the SQL / params output in the Heroku logs. You can do this by adding the line shown below to the config block within your production.rb file:
MyAppNameHere::Application.configure do
# add this line
config.logger = Logger.new(STDOUT)
end
By the way, setting the log level to debug just means that Rails.logger.debug will output to the logs when you're on Heroku
In your production.rb add config.log_level = :debug and redeploy. That will give you the same logs as development mode :)
The detailed log you want is generated by the function start_processing in log_subscriber.rb.
action_controller/log_subscriber.rb:
def start_processing(event)
payload = event.payload
params = payload[:params].except(*INTERNAL_PARAMS)
info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
info " Parameters: #{params.inspect}" unless params.empty?
end
I checked with rails 3.0.4 in development and production environment. In both environments, we have the detailed logs.
This is an info level log. That's why the debug log level is not changing the output.
I installed the plugin used by heroku rails_log_stdout (Heroku logging) but I still have the desired output.
Right now, I can't test with heroku to find out why you don't have all the logs.
In the heroku example (see Heroku logging, section log retrieval), we don't see the "Processing" and "Parameters" lines. I think that either this method is not called when the app is running on heroku (it is somehow disabled) or heroku skips logs starting with whitespaces. Could you try to log messages starting with whitespaces and see if heroku is showing them?
Rails doesn't generate those logs when in production mode. http://groups.google.com/group/heroku/browse_thread/thread/d778fafedc9a378a
The real problem is actually due to the way Heroku works in conjunction with rails. The right way to solve this is to add: gem 'rails_12factor', group: :production
See https://devcenter.heroku.com/articles/rails-integration-gems for more info on the matter
Looks like the puma server doesn't play well with Heroku. In my project, I tried everything, but it still wouldn't log. I then replaced Puma with Unicorn, and bam, full logs are being shown.

Resources