Wednesday, November 21, 2012

Installing RADAR on Ubuntu

 DRAFT-DRAFT-DRAFT  Please report any trouble to Prof. Gordon

Assumptions

  1. git client is installed (https://help.ubuntu.com/community/Git)
  2. You have an account with gitorious.org (https://gitorious.org/)
  3. You have created an ssh key and provided your public key to gitorious.org. (https://help.ubuntu.com/community/SSH/OpenSSH/Keys)
  4. You have ruby 1.9.3 and rvm installed.  (http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you)
Preparation

  1. Create a directory into which you want to place your Radar installation. For the sake of this document, we will refer to this directory as $RADAR_HOME
  2. cd $RADAR_HOME. All of the following activity occurs within your current directory as $RADAR_HOME. All file references are relative to $RADAR_HOME.
  3. git clone  git@github.com:rkgordon3/radar.git
  4. sudo apt-get install rake
  5. sudo apt-get install ruby-bundler
  6. bundle install

    If step 7 hangs, comment out the following lines in Gemfile 

    group :test do
            gem 'cucumber-rails', '1.2.1'
            gem 'rspec-rails', '2.7.0'
            gem 'database_cleaner', '0.7.0'
            gem 'factory_girl', '4.1.0'
            gem 'capybara'
    #       gem 'mongoid-rspec', :require => false
    end


    then run bundle install again, then uncomment above lines and run bundle install yet again.

  7. Create a file config/database.yml and put the following in this file:

    development:
       adapter: sqlite3
       database: db/development.sqlite3
       pool: 5
       timeout: 5000

    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test: &test
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000

    cucumber:
      <<: *test

     
  8. rake db:migrate
  9. rake db:seed
Running Server

You can now run the rails server

rails s

This runs server on port 3000. You can change the port with a -p option.

The seeds file populated the development database with a user 
radar-admin@smumn.edu with password as 'password.' You can log in with that user and then add a couple users for your testing. 

Using Oracle

See this post if you are going to use Oracle database with Radar. In this case, you must also modify config/database.yml. Comment out the current values in the development: group and use these:

adapter: oracle_enhanced
database: ecs4
username:#ask Prof Gordon
password:  #ask Prof Gordon
host: #ask Prof Gordon 

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.

Wednesday, September 26, 2012

Import Students/Drop Students

Currently, updating student database is a manual procedure. It will remain so until we fix index problem in staff_organizations table.

Here are the steps. Replace $RADAR_APP_HOME with root directory of Radar app.

% cd $RADAR_APP_HOME
% cd script
% ftp -s:ftp_cmds
% ruby load_students.rb production
% ruby drop_students.rb production

The file ftp_cmds is not checked into gitorious as it contains passwords. You will have to ask Prof Gordon for it.

Friday, June 1, 2012

Creating new User Type (ability)


  1. Create entry for new access level in database. Probably the best way to do this is via rails console.The only fields that need to be defined are :name and :display_name. :name should have no spaces. For this discussion, assume the new access level is named TempUser.
  2. Create ability in relevant model for organization, e.g. app/models/residence_life_organization.rb. There is a naming convention that must be followed when creating ability. The ability should be the singularized, tableized value of :name field (See Step 1 above). For example, the ability for TempUser should be temp_user. (Note: a tableized name is a name separated at upper-case letters with inserted underscores). If you fail to correctly define the ability name, you will see a message like:
  3. No role for cs.temp@smumn.edu in Residence Life
    in the log.
  4. Give :assign abilities to appropriate administrative users. Currently, administrator and system administrator can create (assign) new users in organizations. These changes are also made in organizational abilities file, e.g. app/models/residence_life_organization.rb.
  5. Give :create, :update, :destroy abilities to appropriate administrative users. These changes are also made in organizational abilities file, e.g. app/models/residence_life_organization.rb. 

Wednesday, February 29, 2012

Wednesday, February 15, 2012

Rails javascript Tag

Using javascript tag allows you to include ruby code in javascript so that it gets interpreted when code is generated.

Here is an example wherein format for AnyTime.picker is dependent on the report for which the approach time field is rendered.

<%= javascript_tag "AnyTime.picker( 'approach_time', {   format: '#{@report.approach_time_format_picker}',   firstDOW: 0 } );"

Sunday, February 12, 2012

ActiveRelation in Session

If you ever see this:

TypeError (no marshal_dump is defined for class Mutex):

You are probably trying to store an ActiveRelation in the session.

Thursday, February 9, 2012

Adding a New Report

Adding new reports for ASC is straightforward, though not yet automated. This example illustrates adding the TutorDropInReport.

  1. Add entry to routes file:
    resources :tutor_drop_in_reports, :controller => "tutor_reports"
  2. Create empty model TutorDropInReport that extends Report.
  3. Create ReportType entry. See seeds.rb
  4. Create field descriptors. See seeds.rb
  5. Add to menu view, views/organizations/orgs/AcademicSkillsCenterOrganization/_reports_menu.html.erb
  6. Add to MY_REPORTS in models/academic_skills_center_organization.rb
  7. Update config/locales/en.yml

Friday, January 20, 2012

Migration Status: How to Determine Pending Migrations

Here is the ticket for determining which migrations are pending against a database:

C:\>rake db:abort_if_pending_migrations

You have 33 pending migrations:
20110921040743 CreateTutorReports
20110922005523 CreateCourses
20110922005721 CreateEnrollments
20110922011612 AddCourseIdToEnrollments
20110922011813 AddStudentIdToEnrollments
20110922012010 AddDepartmentToCourses
20110922012119 AddCourseNumberToCourses
20110922012242 AddSectionToCourses
20110922012404 AddSemesterToCourses
...