Home > Bug, Ruby on Rails > Bug in Rails’ observe_field and prototype.js

Bug in Rails’ observe_field and prototype.js

I tried using Rails’ observe_field yesterday, and it didn’t work if you specified the :frequency option with the value set to less than or equal to 0.

Code snippet:

<%= observe_field :item_id,
:frequency => 0,
:update => “this_part”,
:url => {:action => ‘new’},
:with => “‘item_id=’ + value” %>

You would have got a javascript error in prototype.js at

 onElementEvent: function() {
var value = this.getValue();
if (this.lastValue != value) {
this.callback(this.element, value);
this.lastValue = value;

It would seems that nothing was happening if you weren’t on the look out for javascript errors.  No big issue.  Just remove the :frequency option and you are good to go.  The frequency option works fine for values greater than 0.

My version of Rails: 1.2.2

Categories: Bug, Ruby on Rails
  1. March 20, 2007 at 10:13 pm

    Some people will say that it’s not a bug. If :frequency is 0, then it doesn’t make sense to include it, so leave it out.

    I classify it as a bug because the book and the document says that you can set :frequency to 0 or less if you want actions taken immediately for an event on the observed field.

    I set it to 0, it doesn’t work as it said it should. So it’s a bug.

    If I missed anything, or if anyone knows how to make :frequency work with 0 or less, please correct me!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: