Rails 5.0.0.beta3 thinks it is in production mode when it isn't

Hi All!

Another problem. I am using Rails 5.0.0.beta3 with a minor javascript
file (115 lines). I have encountered the following problem several
times in the past two days. In both earlier cases, I ended up returning
to the master branch and starting over (there were very few changes in
those two branches, I hadn’t gotten very far). Now I have it very close
to being finished and I can’t seem to get it to work like it was a few
minutes ago. Unfortunately, I have not committed my changes frequently
enough (dumb, I know) so I will have to start over again. (I can copy
the edited files out of the git tree, create a new branch and copy them
back, but I would like to get to the bottom of this weirdness before I
do),

I am working in development mode. I can edit and test the .js.erb
file in assets with no problems for hours on end. Most of the time I
don’t even have to restart the server (usually when I edit routes.rb).

Suddenly, it gives me an error message about needing to pre-compile
the js file in production mode by editing a config file and
restarting. Without changing the config (as it recommends) when I
restart the app it no longer loads the javascript file, and none of the
routines in it execute anymore. It also ignores any edits that I make
to that file. In one of the earlier cases I did edit the config file as
it requested, but that did nothing to solve the problem.

I don’t have any idea what I might have changed to cause this. I looked
at the git status and I have only changed/created four files:

  1. The layout file that originally had the js code (was moved to the
    newly created js.erb file)
  2. The controller file
  3. The routes.rb file, and
  4. The newly created js.erb file.

The last edit was to correct a typo in the js.erb file.

The program works (loads the js from the layout file and does everything
that is already coded) when I switch back to the master branch, but as
soon as I go to the working branch, the problem comes back.

The rails log seems to show it loading pre-compiled scripts after it
breaks, while before it seems to be getting files from the assets
directory. (Not sure about this).

I tried both Firefox and Chrome and both show the same behavior (not
surprising).

I double checked that RAILS_ENV=development and it is. This has been
setup for years and only changes when I explicitly set it to production
(rarely). It returns to development whenever I login.

Where should I start looking for this problem?

Thanks,

Don

On 8 March 2016 at 05:14, Donald Z. [email protected] wrote:

create a new branch and copy them back, but I would like to get to the
bottom of this weirdness before I do),

I am working in development mode. I can edit and test the .js.erb file in
assets with no problems for hours on end. Most of the time I don’t even
have to restart the server (usually when I edit routes.rb).

Suddenly, it gives me an error message about needing to pre-compile the js
file in production mode by editing a config file and restarting.

Can you copy/paste the full error message please. I have seen errors
like this where the message is a bit confusing.

Also it would be worth comparing the logs before and after it fails to
see what the difference is.

Colin

Hi Colin,

This seems to be a combination of problems.

I did a git diff between the master branch (which worked correctly - up
to the place where I was coding) and the working branch (which was NOT
working :wink: ). There was nothing unusual, only 4 files changed and
nothing that would cause Rails to think it was in production mode. I
somehow lost the part of the log that had that strange error message,
and it hasn’t re-appeared (yet. I sure hope never).

The part of the problem where it ignored my edits seems to be two-fold.
Part of it went away when I cleared cache in my browsers, The second
seems to be that Rails is now ignoring changes in .js and .js.erb
files. It’s very hard to explain, because it was processing them
yesterday till I got that weird error message.

I finally did what I threatened to do yesterday. I copied the modified
files outside the git tree and created another branch (4 for this part
of the project so far). I copied the problem files one-by-one into the
new branch, starting with routes.rb (nothing would work if the routes
were missing). Tested and it worked. I copied the controller, tested
it, and it passed. I copied the calendars.js.erb and tested it. It
failed (many alerts in the file, none activated), only the alert I put
in in calendars.coffee showed up. Deleted calendars.coffee and
restarted. No change!!! The alert in calendars.coffee still appeared
(the file was GONE). None from the javascript file.

At this point I discovered that coffeescript is not a superset of
javascript. I copied the javascript line-for-line into a new
coffeescript file and Rails barfed. I have never used coffeescript, but
from the looks of things, I needed to learn fast.

After a few hours of editing, reading the manuals, testing and more
editing, I got the javascript translated into coffeescript.
Incidentally, in the process I totally hosed the javascript file, but
Rails didn’t seem to mind. It just ignored anything I did to that
file. I’m not proficient in coffeescript, but…

In the long run, I got the thing working. There has not been an
instance of the “You need to pre-compile the javascript file”.

If anything like before happens, I’ll copy the appropriate log entries
and send them to you.

My new mantra is “commit early, commit often”. :smiley:

Thanks,

Don

On 8 March 2016 at 23:22, Dave B. [email protected] wrote:

very much like the asset pipeline is being used. And clearly, with the
second request, when the PNG is correctly placed, suggests that the asset
pipeline is in use.

I haven’t done anything with respect to the asset configuration. Everything
is just as ‘rails new’ generated. I have noticed there is now an
app/assets/config/manifest.js file that appears to be similar in nature to
app/assets/javascripts/application.js but I don’t know how to use this file.

I think the first log you provided is exactly what one would expect in
development mode. It is requesting each of the assets separately. If
it were in production mode all the js would have been precompiled into
one file, for example.

The second log does seem odd however. Have you tried restarting the
server? I suspect the error might go away. Perhaps it is confused by
not finding it the first time, or something along those lines. Still
a bug though, but I have been unable to replicate it.

Colin


At this point I discovered that coffeescript is not a superset of
javascript. I copied the javascript line-for-line into a new coffeescript
file and Rails barfed. I have never used coffeescript, but from the looks
of things, I needed to learn fast.

Just for reference, I believe that you can use straight js in rails 5.
If you use the extension .js then it will interpret them as js. I
can’t guarantee this as I have not done it, but I am fairly confident
it is correct.

Colin

Colin, thanks for pointing out the fact that each asset, JS and CSS in
particular, are being fetched individually, that wouldn’t happen with
the
production asset pipeline running. Strange still about the way images
are
being handled. By restarting the server, with the asset already placed
things work as expected. I just don’t ever recall having to start and
stop
the server to add images before.

Colin, are you running beta3? I have a simple test project against
beta1
that I will circle back to and see if this same behaviour is present.

Thanks,
Dave

I believe a similar thing is happen with my install of Rails 5. It
appears
to me that the development environment is attempting to serve assets via
the pipeline. For my experiment I use an image_tag to pull down an
image.
In the first load case the PNG requested is not present in
app/assets/images. For the second request I have copied the PNG into
place. Below is the console trace:

dave@dave-MacBook:$ rails -v
Rails 5.0.0.beta2

dave@dave-MacBook:$ rails s
=> Booting Puma
=> Rails 5.0.0.beta2 application starting in development on
http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Puma 2.16.0 starting…

  • Min threads: 0, max threads: 16
  • Environment: development
  • Listening on tcp://localhost:3000

Started GET “/sign_in” for 127.0.0.1 at 2016-03-08 14:58:50 -0800
Processing by UserController#sign_in as HTML
Rendered user/sign_in_up.html.haml within layouts/application
(786.7ms)
Rendered shared/_header.html.haml (97.8ms)
Completed 200 OK in 938ms (Views: 910.9ms | ActiveRecord: 0.0ms)
Started GET
“/assets/bootstrap/bootstrap-theme.self-3598a44d4c6ec016d76dc796536975c136b9cbff9e9f22216088b542fa658481.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/bootstrap/bootstrap.self-598365399e6ae8f5a456a189663bac8ef9b8996ace38626328403f280fd63400.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/vendor_manifest.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/font-awesome.self-c1a7a80b6536c3397a1a212c9bd22298ae69260ee343d00b60d7f41fa54a59a8.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/search.self-f4ce997ae0874a91dccf3e609f24a0a61e4e51021836329d7e0a519173ce233b.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/shared/main.self-36922b9ab4cde4dd04c7393ca03177e067982525ad494bd05c8a7478c47632b7.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/shared/lesshat.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/user.self-8c01dbddb022ddbff9bb74f8baf99e5139bdaee2997404853c6a9d106444bbe5.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/application.self-0e31f1d30f689436ae56e463f6474eb99704af8bbed5fc320a66ac33afb59c2b.css?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/jquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/action_cable.self-5cc84f1a95a47f68c4e64db6ffd98e141a568a28f49b78fa82712f809692630f.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/jquery_ujs.self-d602bdfe68ffc63b9f9cc512872aa3cfff046228a0a36e90dd476e8ef54c1b09.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/cable.self-e475a14c2de96c3e8b6ec198f31d9dce665cb56a1de35233ff6b6e4aed8af083.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/search.self-a8e5021a341c867ddd784bff1c4fbf355ce26dcc93e7c17da4db0d93a686689f.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/channels/search_results.self-62b81ec1b2eb773ca7e98df9f8bc81b48f8c4a9790c5519269f3685d8519b70a.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/user.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/bootstrap/bootstrap.self-d0e973a52d36a01036265aeefaf2d1ae3499d2cb231a9be3bd846432daf231de.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/vendor_manifest.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/application.self-afe802b04eaf1de2ea762489c83c08aa4c4ff3ff13c21566e43cb710683f5abc.js?body=1”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/logo-128x128-1a26fea2556eb3e28a2e964cfb9c354196bdfc6255f8d275a457c4da2bda3f9a.png”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET “/images/facebook-32x32.png” for 127.0.0.1 at 2016-03-08
14:58:51 -0800
Started GET
“/assets/twitter-32x32-4544d620700b86d9096fd28c0cf9696d398938cd1d897d59982a73096ee47657.png”
for 127.0.0.1 at 2016-03-08 14:58:51 -0800
Started GET
“/assets/google-32x32-27128aa0a975258793fbd777417ee89b7dd14f99ec4ca974f6254ed284af8618.png”
for 127.0.0.1 at 2016-03-08 14:58:52 -0800

ActionController::RoutingError (No route matches [GET]
“/images/facebook-32x32.png”):
actionpack (5.0.0.beta2)
lib/action_dispatch/middleware/debug_exceptions.rb:53:in call' web-console (3.1.1) lib/web_console/middleware.rb:131:in call_app’
web-console (3.1.1) lib/web_console/middleware.rb:28:in block in call' web-console (3.1.1) lib/web_console/middleware.rb:18:in catch’
web-console (3.1.1) lib/web_console/middleware.rb:18:in call' actionpack (5.0.0.beta2) lib/action_dispatch/middleware/show_exceptions.rb:31:in call’
railties (5.0.0.beta2) lib/rails/rack/logger.rb:36:in call_app' railties (5.0.0.beta2) lib/rails/rack/logger.rb:24:in block in call’
activesupport (5.0.0.beta2) lib/active_support/tagged_logging.rb:70:in
block in tagged' activesupport (5.0.0.beta2) lib/active_support/tagged_logging.rb:26:in tagged’
activesupport (5.0.0.beta2) lib/active_support/tagged_logging.rb:70:in
tagged' railties (5.0.0.beta2) lib/rails/rack/logger.rb:24:in call’
actionpack (5.0.0.beta2)
lib/action_dispatch/middleware/request_id.rb:24:in call' rack (2.0.0.alpha) lib/rack/method_override.rb:22:in call’
rack (2.0.0.alpha) lib/rack/runtime.rb:22:in call' activesupport (5.0.0.beta2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call’
actionpack (5.0.0.beta2)
lib/action_dispatch/middleware/load_interlock.rb:13:in call' actionpack (5.0.0.beta2) lib/action_dispatch/middleware/static.rb:136:in call’
rack (2.0.0.alpha) lib/rack/sendfile.rb:111:in call' railties (5.0.0.beta2) lib/rails/engine.rb:522:in call’
puma (2.16.0) lib/puma/server.rb:557:in handle_request' puma (2.16.0) lib/puma/server.rb:404:in process_client’
puma (2.16.0) lib/puma/server.rb:270:in block in run' puma (2.16.0) lib/puma/thread_pool.rb:106:in call’
puma (2.16.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread’

Started GET “/sign_in” for 127.0.0.1 at 2016-03-08 15:02:11 -0800
Processing by UserController#sign_in as HTML
Rendered user/sign_in_up.html.haml within layouts/application (80.1ms)
Completed 500 Internal Server Error in 85ms (ActiveRecord: 0.0ms)

ActionView::Template::Error (Asset was not declared to be precompiled in
production.
Add Rails.application.config.assets.precompile += %w( facebook-32x32.png ) to config/initializers/assets.rb and restart your server):
11: .row
12: .col-sm-4.col-sm-offset-4.col-xs-12
13: = link_to(provider[:link],:class => ‘btn-grey btn-block
oauth-link’) do
14: = image_tag(provider[:image],:class => ‘oauth-image’)
15: .text-center
16: = provider[:label]
17:
app/views/user/sign_in_up.html.haml:14:in block (2 levels) in _app_views_user_sign_in_up_html_haml__345370075_101410280' app/views/user/sign_in_up.html.haml:13:in block in
_app_views_user_sign_in_up_html_haml__345370075_101410280’
app/views/user/sign_in_up.html.haml:10:in each' app/views/user/sign_in_up.html.haml:10:in _app_views_user_sign_in_up_html_haml__345370075_101410280’
app/controllers/user_controller.rb:13:in `sign_in’

Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/actionpack-5.0.0.beta2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
(19.1ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/actionpack-5.0.0.beta2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
(6.5ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/actionpack-5.0.0.beta2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
(1.5ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/actionpack-5.0.0.beta2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb
within rescues/layout (62.9ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/_markup.html.erb
(0.6ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/_inner_console_markup.html.erb
within layouts/inlined_string (0.4ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/_prompt_box_markup.html.erb
within layouts/inlined_string (0.5ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/style.css.erb
within layouts/inlined_string (0.5ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/console.js.erb
within layouts/javascript (34.4ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/main.js.erb
within layouts/javascript (0.7ms)
Rendered
/home/dave/.rvm/gems/ruby-2.2.3@community/gems/web-console-3.1.1/lib/web_console/templates/index.html.erb
(61.6ms)

When rails starts is correctly calls out that it is running in
development
mode. However, the way it is pulling down assets on the first request
looks very much like the asset pipeline is being used. And clearly,
with
the second request, when the PNG is correctly placed, suggests that the
asset pipeline is in use.

I haven’t done anything with respect to the asset configuration.
Everything is just as ‘rails new’ generated. I have noticed there is
now
an app/assets/config/manifest.js file that appears to be similar in
nature
to app/assets/javascripts/application.js but I don’t know how to use
this
file.

Dave

On 10 March 2016 at 03:36, Dave B. [email protected] wrote:

Colin, thanks for pointing out the fact that each asset, JS and CSS in
particular, are being fetched individually, that wouldn’t happen with the
production asset pipeline running. Strange still about the way images are
being handled. By restarting the server, with the asset already placed
things work as expected. I just don’t ever recall having to start and stop
the server to add images before.

You should not have to. As I said if that is happening it is a bug.
It may already have been fixed, I don’t see an open issue for it.

Colin, are you running beta3? I have a simple test project against beta1
that I will circle back to and see if this same behaviour is present.

Yes, I am using beta3. First I suggest searching the rails 5 issues
to see if it has already been fixed. If it is not there then if you
can get a repeatable failure then try it using the edge version of
rails to see if has been fixed already. If it has not been fixed then
report an issue.

Colin