Tuesday, 26 January 2010

GWT development mode and Rails embedded applications

GWT 2.0 has development mode which supports debugging by a cunning use of browser-based JavaScript communicating execution status back to the GWT server.

To enable this, GWT sends a debugging JavsScript package to the browser and relies on you setting the parameter gwt.codesvr. GWT helpfully tells your what the correct value for this should be in the development mode startup message. Usually it is

The GWT payload reads the parameters passed to the web page which poses a problem for embedded GWT applications in Rails with external frameworks such as when using smartGWT. The reason is that the Rails routing system means that embedding
in URLs does fit well and in some cases will break the Rails parameter passing mechanism.

Likewise, attempting to set the parameter in the JavaScript load doesn't work:

Embedding the setting into the rendering and redirect sections of your controllers runs the risk of this code remaining in your system when you deploy. Not only that, but it's messy and requires you to change your code prior to deploying.

And easy solution is to let Rails do the heavy lifting for you. You only want the GWT debugger to be on in the development environment.

Rails 2:
In your environment.rb file, add this at the bottom of the file:
   # Setting for GWT
   if ENV['RAILS_ENV'] == 'development'

Rails 3 and 4:
in the file:
in the files:

This will set the global $GWT_DEBUG which you can then append to the URLs that load up embedded Web 2 applications based on GWT. When you deploy live, no code changes are needed.

Now in your controllers you can simply create URLs like this:
   redirect_to '/myurl'+$GWT_DEBUG

No comments:

Post a Comment