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.

Wednesday, November 30, 2011

Gem Versioning

Within Gemfile you can constrain which version or versions of a gem your application is dependent upon.

Any gem inclusion without a version number indicates 'latest' version of gem should be used.

Specifying a gem as such:

gen 'foo', '=3.0'

indicates a specific version must be used.

Specifying a gem as such

gem 'foo', '>= 3.0'

indicates a version >= 3.0 is suitable. In general, you get what you expect from

= Equals version
!= Not equal to version
> Greater than version
< Less than version
>= Greater than or equal to
<= Less than or equal to

Gem versions can also be specified with the 'approximately greater than' operator. This operator increment final digit of a version up until next significant digit would turn over. So, a gem specification of

gem 'foo', '~> 3.1'

is satisfied with any version from 3.1 up to 3.9. inclusive. If three digits are specified in a version number used with ~> operator, as below

gem 'foo', '~> 3.1.1'

then the gem versions compatible with the application are 3.1.1 through 3.1.9, inclusive.

Autocomplete Details

https://github.com/crowdint/rails3-jquery-autocomplete

Wednesday, June 22, 2011

Rails: Calling Controller Action using onclick and Ajax (remote_function)

Say you want to call the update_reasons action in the reports controller in response to an onclick on a checkbox.

First, of course, you need the route in config/routes.rb



match "/reports/update_reasons" => "reports#update_reasons"



And, of course, the action...I just echo relevant arguments in this version.

Note, I render "nothing" because operation does not result in any view change beyond status change of checkbox which is managed by browser.


def update_reasons
  checked = params[:checked]
  params.each do |key, value|
    if /reasons_(\d+)/.match(value) != nil
      logger.debug("update reason #{$1} to #{checked}")
    end
  end
  respond_to do |format|
    format.js { render  :nothing => true }
  end
end


Using the check_box_tag, you will include on :onclick parameter. The value of :onclick is javascript. The "best" way to generate that javascript is using remote_function helper. I use the :with parameter to send request parameters

with the Ajax call. Notice in ruby code above reference to parameter names appearing in value of :with string in view code.



Here is my view code:



<% reasons.each do |infraction| %>
    <% rf =  remote_function(
       :url => { :controller => 'reports', 
               :action => :update_reasons },
       :with => '\'reason=\'+ this.id + \'&checked=\' + this.checked')  %>
    <%= check_box_tag "reasons[#{infraction.id}]", 
      infraction.description,
      false ,
      :onclick => "#{rf}",
      :class=>:"iToggle", :title=>"YES|NO" %>
    <%= infraction.description %>  
  <% end %>



If I expect some server-side generated change to view, I could include an :update argument to remote_function. This parameter names a div into rendered output is placed.

I admit I took a lazy approach by placing value of remote_function to a local variable. After much hair-pulling,I gave on trying to get quotes right with remote_function as direct value of :onclick parameter.

Monday, June 20, 2011

Contact Reasons Associated with a Report

I have added a method to RelationshipToReport model that returns a list of only those 'relationships' that apply to a given report type. The method name is for.

Here is an example usage:

infractions = RelationshipToReport.for(report)
infractions.each do |infraction|
...
end

Wednesday, April 13, 2011

Javascript and Rails

I have learned two things in the last 24 hours:

Javascript in partials

You can't place <% javascript_tag do %> in partials if you expect your javascript to be seen.

Multiple Requests as a Result of Form Submit

Multiple inclusions of js files, e.g. rails.js can cause multiple events/requests to be posted as a result of form submit. This is very hard to debug, but rails server shows, e.g. multiple GET requests being performed.

Monday, April 4, 2011

Cucumber on Windows

You must augment instructions from RSpec book for installing Cucumber on Windows. Specifically, you need to download MinGW for gcc (c compiler) and make. MinGW is
available from http://www.mingw.org/

When installing MinGW, make sure you select MSYS Developer Kit when stepping through installer.

To access gcc, you need to augment PATH environment variable to include C:\MinGW\bin.
To access make, you need to include C:\MinGW\msys\1.0\bin on your PATH environment variable. See Control Panel->System->Advanced->Environment Variables to edit PATH environment variable.

Wednesday, March 2, 2011

Default Values in ActiveRecord Fields

Looking at some of the incident report controller code, I noticed a few rogue constants floating around. They appeared to be primary key values of default values for, e.g. infractions.

Let me propose an alternative: set the default in the ActiveRecord code. There are a variety of approaches discussed here.

Check it out.

So, we should consider something like:
class RecordedInfraction < ActiveRecord::Base
  after_initialize :default_values

  private
    def default_values
      self.infraction_id ||= Infraction.find_by_name("FYI").id
    end
end

That way we can reduce the WTFs when reading our code.

Sunday, February 13, 2011

Elevator Pitch Competiton!

Dear Becca,

Congratulations!! The judges of the elevator pitch competition have named you a winner in our recent event.
I have requested that a check for $100 be sent to you via campus mail. Please allow the Business Office a couple of weeks to process this request.

On behalf of the Kabara Institute for Entrepreneurial Studies at Saint Mary’s University, thank you for participating in our Elevator Pitch Competition, and congratulations!


Best wishes for continued success!

Teresa Speck

Thursday, February 10, 2011

Helpful Rails Links

Getting Started

Mirgrations

Associations

Rails ERD

SQLExplorer Plug-in

Useful Rails Stuff

While messing around with Rails, I found it very difficult to keep track of my nascent model because the information is so widely dispersed. The table information is in the migration files. The association information is defined by the model files. And all sorts of naming conventions have to be remembered.

So, I got to thinking: Maybe there is a tool which can digest a Rails application and generate an ER diagram.

Guess what? We are in luck. A quick google of 'rails er diagram' discovered Rails ERD. The installation is quite easy. Drop a few lines in your Gemfile and run bundle install.

Once installed, I run the tool as such:

rake erd filetype=dot attributes=foreign_key,inheritance,content inheritance=true

in my application directory. The output of the above command is a file named ERD.dot.

You can then convert the ERD.dot file into a png file with a tool provided by Graphviz (You can grab Windows installer at \\csfile\software\graphviz). Once installed, you get the dot command which can be used as follows:

dot -Tpng ERD.dot > yourmodel.png

You can view the png file in any browser.

Here is what I have so far:

Which you really can't see too well, so I will post a copy to Blackboard under Course Materials.

Wednesday, February 9, 2011

Wandering Around SQLite Database

It may be useful (take my word for it) to be able to directly examine the contents of your SQLite database as it grows with data for our RADAR application. Further, it may be useful to be able to directly manipulate the contents of said database, for example, adding records and establishing explicit associations.

For such purposes, may I recommend SQLExplorer plug-in for Eclipse coupled with SQLite JDBC driver. The latter you can find at \\csfile\software\sqlite\sqlitejdbc-v056.jar.

Big Picture:
  1. Install SQLExplorer plug-in
  2. Drop driver jar into your Eclipse plugin directory
  3. Configure SQLExplorer to see SQLite driver

For the last step I can help if anyone is interested. I am not going to go through trouble explaining it if I have no customers.

Friday, January 28, 2011

Erratum

There was incomplete information in the directions to view demo of openreports below. I have updated the post to be more clear.

Robert's Rules of Order

I hereby move that if the RADAR Detectors continue to run their meetings according to Robert's Rules of Order and, further, if the associated minutes duly record such formality, said minutes will be refused.

I second the motion.

All in favor.

Aye.

All opposed.

The motion carries.

Some Ideas/Questions/Suggestions, not all original

  1. Sketch a domain model
    • What are domain classes?
    • What are relationships among domain classes?
    • What are responsibilities of each domain class?
    • Pick the easy ones first.
    • Which ones do you need to refine first N (N is small) user stories?
  2. Pick a User Story, refine it.
    • Design a page layout template. This can be simple because real estate is at a premium, but Rails provides nice support for generalizing a layout across entire application.
    • Finalize (conditionally) what each "page" looks like, that is, what fields it contains.
    • Build in navigation: implement flow we charted in meeting.
    • Ask: What are implications of UI and UI flow on model?

    It may not be a bad idea to prototype user story on desktop; get a quick feel for flow.

  3. Consider data-flow of report submission.
    • One of first goals should be to get an end-to-end pipeline in place from screen to backend. This can be rough but it will provide context for discussion of further design.
    • I imagine a Rails SubmissionController on the back-end of this pipeline. Its first implementation is real simple: generate a text file.
    • I also imagine some sort of NotificationService for distributing reports (in whatever form). Its first implementation is real simple: print to console.
  4. Using Rails scaffolding support, we can very easily build some cheap admin screens for:
    • Adding students
    • Adding users (ie RA, Hall Directors)
    • Defining buildings, etc.
    • Adding infractions

    I would encourage getting started on this as a way to start to shake out model and as a way to familiarize yourself with Rails.

  5. Start asking: How is a report modeled?
    • I wonder if something like this would be useful: http://oreports.com/ (http://oreports.com/docs/or-install-guide-3.0.html). This package pulls from relational database.
    • If you grab the folder \\csfile\software\openreports\openreports-tomcat and drop it in at C: on a windows machine, you can see some of the capabilities of openreports.
      1. Copy folder to c:
      2. Change directory ino openreports, ie. cd openreports
      3. Run startup.bat script
      4. In browser, visit by http://localhost:8080/openreports (assuming you are on same machine)
      5. User/password = admin/admin.

      What you are viewing, of course, is a demo app. Behind the demo is the kind of code we would write to generate reports from sql.

    • One nice thing about this package is that it can generate either HTML or PDF!

Tuesday, January 25, 2011

More on REST

Here is a little better explanation of what a RESTful API is.

Remember, there is no REST for the wicked.

Managing Images

From what I have been hearing, one of the most important wishes for RADAR is the ability to browse/search images of students in order to confirm identity and, then, to attach student images to Incident Reports. Additionally, it would be nice--though I have not heard this from ResLife--to be able to attach pictures to Maintenance Reports or pictures of damage to Incident Reports.

In the spirit of decoupling as much as possible from SMU infrastructure, I want to suggest the team look into something like Gallery. Gallery is an open-source image server that provides a RESTful API. It appears quite easy to use and a cinch to install.

I mention Gallery because a CS394 student (Owen Kuemerle) will be using it to support the Android application he will be writing for the course. He has a server installed already and has some familiarity with the API. I think there is a chance for some synergy here. Owen is open to cooperation.

Yes, eventually, we would have to ingest images from SMU photo gallery, but we can figure that out when the time comes. And, if we are serious about thinking beyond SMU, we have to solve the problem of "populating RADAR database" anyway.

Please talk about this as a group.

Saturday, January 22, 2011

Beyond RADAR

There has been some justifiable concern that, perhaps, there will not be enough work to for eBusiness folks. So, I got to thinking. I thought: Think beyond RADAR (as a class project).
  1. Are there other applications on campus that could benefit from mobile reporting? Security? Maintenance? If we think generally enough about what it means to submit a report, we may be able to solve a more larger problem then we originally intended...as long as primary goals are met. If we want to pursue such questions, maybe the eBusiness people should set out identifying some stakeholders in such an endeavor. Do some "market research." Measure interest. Report back.
  2. Build a business plan for building out RADAR such that we could market it to other institutions. What is competition? What, if anything, are other schools doing? What other schools would be interested in something like RADAR?
  3. Develop marketing collateral as-if we were going to market RADAR beyond the confines of SMU.
Those are just three ideas. I bet the team can come up with more.

Thursday, January 20, 2011

What Do We Know Right Now

Some not entirely random thoughts and questions regarding the RADAR project.

What do we know right now before talking to the "customer" (Brendan Dolan, ResLife)? What can we model now? What detail can we start to sketch in regarding overall system architecture?

Let me take a stab at these questions. Hopefully, my thoughts can jump start your thinking.

You have the reports that ResLife currently uses. They pretty much define what it is we need to produce. They may not be perfect buy they start to tell a lot of the story.
  1. How can we model these reports? Is there an abstraction we can apply that will allow us to proceed not knowing precisely what ResLife wants and capable of easily comprehending changes?
  2. How do we persist report data? Flat file? PDF? XML? Relational Database? Which approach is easiest? Which approach is amenable to post-processing, ie. trend analysis, general queries? Do we need to support such queries? Can we design for such support without committing to it upfront?
  3. Who are the actors in our system? RAs. Hall Directors. How do they interact with the system? How are they notified of 'events'?
  4. Can we model students and buildings and areas in a quick way to get something up and running?
  5. Basic Question: What can we build NOW with imperfect knowledge?

I think we know most about reports. I think that is a good place to start. How do we model them? How do we move them around? How do we persist them? How do we generate them?

Start thinking in terms of Reports NOT in terms of this report or that report.

Continuous Integration + Ruby + GIT

Here is a post on CI + Ruby + GIT. CI + Ruby + git

and a user story http://elabs.se/blog/7-continuous-integration-testing-for-ruby-on-rails-with-integrity

git

I would suggest checking out

http://git-scm.com/

for version control.