Friday, June 26, 2009

Tracking value changes in ActiveRecord objects

Info about getting to old / new values on activerecord objects:

http://ryandaigle.com/articles/2008/3/31/what-s-new-in-edge-rails-dirty-objects

This can be useful if validation varies based upon the prior state of the the object, etc.

Rails Time Zone Support

A good summary of how to support users in different time zones:

http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/

Thursday, June 11, 2009

Ext JS with Rails

Trying to get ExtJS working with Rails...

One of the first steps described in the Ext tutorials is just getting a page set up referencing the javascript libraries: http://extjs.com/learn/Tutorial:HTML_Page_Setup

Unfortunately, that example didn't work in rails. However, taking some suggestions from here, putting this in the head of a rails layout seems to work:

<%= stylesheet_link_tag '../javascripts/ext/resources/css/ext-all' %>
<%= javascript_include_tag 'ext/adapter/prototype/prototype.js' %>
<%= javascript_include_tag 'ext/adapter/prototype/effects.js' %>
<%= javascript_include_tag 'ext/adapter/prototype/ext-prototype-adapter.js' %>
<%= javascript_include_tag 'ext/adapter/ext/ext-base.js' %>
<%= javascript_include_tag 'ext/ext-core.js' %>
<%= javascript_include_tag 'ext/ext-all.js' %>

script type="text/javascript" (took off the <>'s from this line for posting)
Ext.BLANK_IMAGE_URL = "../javascripts/ext/resources/images/default/s.gif";
Ext.onReady(function() {
console.info('finally!');
});
/script (took off the <>'s from this line too)

This is basically what's in their tutorial html page, but with extra include tags... It assumes that, as they suggest, you unzip extjs under the rails public/javascripts directory. For the example above, the directory was just named 'ext'.

With that in place (the onReady can be removed), a page using that layout can do something like this:

<%= link_to_function 'Ext Test',
"Ext.MessageBox.show({title: 'Ext Box',
msg: 'Ok?',
buttons: Ext.MessageBox.OK})" %>


(Note: this was Rails 2.2.2 with ExtJS 2.2.1)