Wednesday, October 24, 2012

Redirection and HTTPS

In reports_controller/search_results, we redirect to reports_controller/index.

If that redirect_to looks like:

redirect_to({ :action => "index",   :div_id => 'results', ... })

it fails because we are running https in production.

To fix this, redirect_to needs a :protocol key in its hash, as below:

redirect_to({ :protocol => "https://" ,
                               :action => "index",
                               :div_id => 'results',


But, that does not work in development mode, so best solution is:

redirect_to({ :protocol => Rails.env.production? 
                             ? "https://"
                             : "http://",
                               :action => "index",
                               :div_id => 'results',









Installing Oracle Instant Client on Ubuntu

The Oracle gem for Rails is ruby-oci8.

To run Radar against Oracle on Ubuntu, you need 'instant client' installed. Directions for this are here.

Radar is currently (as of 10/12) running ruby-oci8 2.0.6 gem. Hence, when installing on Ubuntu, you will run across the following in error log.

  Do you install glibc-devel(redhat) or libc6-dev(debian)?
  You need /usr/include/sys/types.h to compile ruby-oci8.
 
The fix is:

$ sudo ln -s /usr/include/linux/ /usr/include/sys
 
This is described here.

Tuesday, October 23, 2012

Running Script within Radar Environment

You can run a ruby script within rails environment by adding the following two lines to head of script.

require File.join(File.dirname(__FILE__), "..", "config", "boot")
require File.join(File.dirname(__FILE__), "..", "config", "environment")

These two lines setup the rails environment, e.g. ActiveRecord. Your script now has entire Rails/radar set of classes available to it.

The script should be run from application home directory as such:


ruby script/your_script.rb

See script/load_students.rb for an example.