Why doesn't better_errors work on cloud 9 ide?

better-errors-gem, cloud9-ide, ruby-on-rails-4

Solution

The trick, I used, to get the 'better_errors' gem working in Cloud9 is setting the value of `TRUSTED_IP` to the public IP address of the computer my browser session is attached to. (As far as I can tell, it has nothing to do with the IP address of the remote server or Cloud9 server addresses.)

I'll outline the process I used to get 'better_errors' working on my Cloud9 workspace, from my Chromebook on my residential network... maybe it will also work for you and others!

- Add `gem "better_errors"` to the development group in the project Gemfile.

- Add `gem "binding_of_caller"` to the project Gemfile.

- Run $`bundle` in the project Cloud9 terminal.

Edit the project config/environments/development.rb file and add the following line of code to the end of the Rails.application.configure block.

BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']

- Create a new "runner" in Cloud9 by clicking "Run" > "Run With" > "New Runner".

Cloud9 creates an basic runner file in a new tab to modify. Replace the contents of this file with following code.

{
   "cmd": [
     "bash",
     "--login",
     "-c",
     "TRUSTED_IP=XXX.XXX.XXX.XXX rails server -p $port -b $ip $args"
  ],
  "working_dir": "$project_path",
  "info": "Your code is running at \\033[01;34m$url\\033[00m.\n\\033[01;31m",
  "selector": "source.ru"
}

- Replace `XXX.XXX.XXX.XXX` in the code above with the local computer's public IP address. (I use http://ifconfig.me/ to find the public IP assigned to my Chromebook.)

- Save the runner file with the name RoR.run into the /.c9/runners path for the project.

- Start the projects server by using this new runner. Click Run > Run With > RoR.

- Use the popup link that Cloud9 displays, after the runner starts the server, to view the app. Enjoy 'better_errors'!

NOTE: I still have not figured out how to automate the process of feeding the external IP address of my local computer into the RoR.run file that lives on the Cloud9 workspace. I just update it manually every time I move to a new network or my external IP address changes.

WARNING: I actually just started learning RoR, so I have no idea if this is the "correct" way to get this gem to work in a cloud dev server/service environment. I also have no idea how safe this would be. I suspect that my solution exposes the 'better_errors' in-browser REPL to all computers that resolve to that same external IP address. If you are working on a sensitive codebase/database please do not implement my solution.

Problem

I'm working on a number of projects on cloud9 IDE, and it's really frustrating that I can't get the better errors gem to work correctly. It isn't supposed to need initializing; it should just work out of the box. However, I still only get the usual ugly red errors page. I should specify that it is included in my gemfile, and I have `bundle install` already. How can I get better errors to work correctly? Is there an installation step I'm missing?

Original source