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
...

Tuesday, December 6, 2011

Looking for make when installing Gem

Sometimes you run into this:


Installing json (1.6.3) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
C:/Ruby192/bin/ruby.exe extconf.rb
creating Makefile

make
'make' is not recognized as an internal or external command,
operable program or batch file.


The gem you are trying to install needs some basic development tools normally found on a Linux/Unix box but not on Windows.

Go here to solve this problem:DevKit for Windows

There are very simple download and install instructions.

Thursday, December 1, 2011

Consuming ID returned by JQuery Autocomplete

This autocompete definition in Participants controller:

autocomplete :participant, :full_name, :display_value => :full_name, :full => true

and this pair of Rails tags:

<%= f.autocomplete_field :name,  
     autocomplete_participant_name_students_path, 
     :id_element => '#participantt_id' %>
  
<%= hidden_field :participant, :id %>

resulting in this HTML

<input data-autocomplete="/participant/autocomplete_participant_full_name"      
  id="full_name" 
  id_element="#participant_id"
  name="full_name" type="text" value="" />  
<input id="participant_id" name="participant[id]" type="hidden" />

does the trick for delivering ID of object found from autocomplete into hidden input field. The value is, then, of course, available as a request parameter when enclosing form is submitted. Your controller accesses this param as such:

Participant.find(params[:participant][:id])


I have tested this in both 0.6.1 and 1.0.4 versions of rails3-jquery-autocomplete gem, using Rails 3.1.1.