Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't better_errors work on cloud 9 ide?

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?

like image 386
elersong Avatar asked Dec 19 '22 09:12

elersong


1 Answers

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!

  1. Add gem "better_errors" to the development group in the project Gemfile.
  2. Add gem "binding_of_caller" to the project Gemfile.
  3. Run $bundle in the project Cloud9 terminal.
  4. 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']
    
  5. Create a new "runner" in Cloud9 by clicking "Run" > "Run With" > "New Runner".
  6. 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"
    }
    
  7. 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.)
  8. Save the runner file with the name RoR.run into the /.c9/runners path for the project.
  9. Start the projects server by using this new runner. Click Run > Run With > RoR.
  10. 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.

like image 194
Grokcodile Avatar answered Jan 19 '23 07:01

Grokcodile