I think this should be simpler. Doing all this just to set RAILS_ENV? There should be an easier way to do this that won't require you to add an external app, a context, rewrite rules, a dispatch.lsapi file.
The 'Rails' context should allow other options than 'development' and 'production'...