Help: error with example in "RJS Templates for Rails" book

Hi,

I’m running through the examples in Cody F.'s “RJS Templates for
Rails” PDF and have hit a small snag.

Have implemented the first part of the expense tracker app, up to the
section about FireBug. All is OK if I try the show view and add an
expense from within Mozilla Firefox. However, if I try it from within
IE and add an expense, I get a pop-up window
RJS error:
[object Error]

then after clicking OK get another pop-up with
new Insertion.bottom(“expenses”, "<tr id=“expense-17”>

test
<td class=“amount”>200.00
");
new Effect.Highlight(“expense-17”,{});
Form.reset(“expense-form”);

If I refresh the show page the new entry is shown (i.e. made it into the
d/b)

I certainly don’t know enough about JS to work out what might be wrong
with the above specific to IE.
Any one else had this issue or know why this might be happening?

Cheers,
Karen

The popups are just debug RJS, basically it tries to run the javascript
and
if it fails, an alert is called with the code it tried to run. Make sure
that the elements you are tryinig to access (expenses, expense-17) are
set
up correctly (names vs ids). IE might act differently than Firefox (I
can’t
remember right off hand) when it comes to accessing DOM elements through
id’s or name’s. I’d have to see the accompaning HTML to know for sure.

Jason

Jason R. wrote:

The popups are just debug RJS, basically it tries to run the javascript
and
if it fails, an alert is called with the code it tried to run. Make sure
that the elements you are tryinig to access (expenses, expense-17) are
set
up correctly (names vs ids). IE might act differently than Firefox (I
can’t
remember right off hand) when it comes to accessing DOM elements through
id’s or name’s. I’d have to see the accompaning HTML to know for sure.

Jason

The code is pulled straight from the book, so hope it’s OK to reproduce
a snippet of the code here :slight_smile:

In the show view, have:

<%= @project.name %>

Expenses

<%= render :partial => 'expenses/expense', :collection => @project.expenses %>
Description Amount
<%= render :partial => 'expenses/new' %>

In the expense partial have:

<%=h expense.description %> <%=h number_with_precision(expense.amount, 2) %>

And in the new partial:

Add an expense

<% form_remote_for :expense, Expense.new, :url => hash_for_expenses_url(:project => @project, :action => 'new'), :html => { :id => 'expense-form' } do |f| %> Description:
<%= f.text_field 'description', :size => 60 %>
Amount:
<%= f.text_field 'amount', :size => 10 %>

<%= submit_tag 'Add Expense' %> <% end %>

So you can see how the DOM ids/names are setup. Does this highlight
what might be the cause?
(Therefore, the error I first posted relates to me adding a new expense
which ends up with an id of 17.)

Thanks
Karen