Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active January 23, 2017 00:35
Show Gist options
  • Save raghubetina/0cb23b75d8e7bd50da5a95d3ef026421 to your computer and use it in GitHub Desktop.
Save raghubetina/0cb23b75d8e7bd50da5a95d3ef026421 to your computer and use it in GitHub Desktop.
Web Console Live Reloading Bug

If, as you’re working on Omnicalc, you are running in to a very confusing issue:

You have made changes to your code in calculations_controller.rb in Atom, (auto)saved it, gone back to Chrome, and refreshed — but nothing happens!

Then read on.

The Problem

As I mentioned in class, this quarter we were trying something new with the interactive Ruby console appearing within Chrome.

My hope was that it would be helpful for you to be able to, for example, start experimenting with @text.length, @text.split, etc, in the word_count task in the web console before having to write down permanent Ruby in calculations_controller.rb.

However, we’ve discovered that the web console is somehow intermittently breaking the live reloading feature of Rails, which allows us to make changes to our code and see them live without having to restart the rails server every time.

This isn’t happening for everyone, nor for every code change, but when it does happen it is very confusing, especially for beginners. I apologize for that.

Solutions

Restarting the server every time

If you notice this happening, you can quit your rails server with Ctrl+C and then start it back up. You will then see the effect of your code change. This is, obviously, a pain, if you have to do it for every code change.

Removing the Web Console

You can remove the web console altogether:

  1. In the file app/views/layouts/application.html.erb, delete the three lines near the bottom that say

    <% if Rails.env.development? %>
      <% console %>
    <% end %>
    
  2. In the Gemfile, which is in the root folder of omnicalc/, find line 42 which says gem 'web-console'. Delete that line.

  3. Shut down your rails server with Ctrl+C.

  4. Run bundle install again.

  5. Start up the rails server again.

Hopefully all of this should resolve the issue, and any time you make a change to your code in Atom and save it, the change should be reflected when you refresh Chrome. If not, please let me know.

The regular old Rails Console

If you remove the web console but still want a console to play with, you can use the regular Rails Console, like we have always done in the past. This won't be quite as handy since you won't have the variables from calculations_controller.rb available for you to play with, but it's otherwise the same. Here is a guide to doing so.

Sorry for the confusion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment