Ajax and observe_field not updating specified DIV

I have a page that has a dropdown which i’m using observe_field on to
make an ajax call back to my controller. The page initially displays
fine. The method is invoked in my controller when i select a choice in
the dropdown and I have an rjs file which is then invoked. The rjs file
looks like this:

page.replace_html ‘embed_calendar’, :partial => ‘shared/calendar’, :year
=> 2006, :month => 5, :table_class => “calendar_helper”

So, I’m assuming that the _calendar.rhtml will be rendered in the
embed_calendar div.

My controller uses a template called main so i have a main.rhtml which
has multiple partials in it for various sections of the page - all with
their own divs. Then I have @content_for_layout in it as well. This is
where my index.rhtml is initially rendered - it looks like this:

<%= start_form_tag(:action => "add") %>

my calendar

<%= select(:month, :id, [['January',1],['February',2],['March',3], ['April',4],['May',5],['June',6], ['July',7],['August',8],['September',9], ['October',10],['November',11],['December',12]] , {:selected => @month}) %> <%= select(:year, :id, [['2005',2005],['2006',2006],['2007',2007], ['2008',2008],['2009',2009],['2010',2010]], {:selected => @year}) %> <%= observe_field 'month_id', :update => 'main_content', :url => { :controller => 'calendar', :action => 'modify_month_view'} %> <%= observe_field 'year_id', :update => 'main_content', :url => { :controller => 'calendar', :action => 'modify_year_view'} %>
<%= render(:partial => "shared/calendar") %>
<%= end_form_tag %>

So when the rjs attempts to write the _calendar partial to the
embed_calendar div - what it looks like it does is write it to the
@content_for_layout section of my main.rhtml. I’ve used the DOM
inspector and saw that this is what it did. So my first question is why
does the rjs not really update the DOM in the div which i specified and
second why does it display the page like its text like this:

ry { Element.update(“embed_calendar”, " \n\t\t\t\t
\n\t\n\t\t\n\t\t\tNovember\n\t\t
\n\t\t\n\t\t\tSun\t\t\t Mon\t\t\t Tue\t\t\t Wed\t\t\t Thu\t\t\t
Fri\t\t\t Sat\t\t
\n\t

Thanks,

Jeff


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails