link_to_function or button_to_function memory usage

I have an full ajax app doing crud operations for contact info for one
section. I was using ajax calls to edit and cancel and also to add a
contact. I am implementing a button_to_function instead of doing an
ajax call to just edit/add/or cancel a contact. I am running into a
memory issue using the button_to_function or link_to_function.

I have this:

<%= link_to_function 'Edit Contact' do |page|
  page[:showcontact].replace_html :partial => '/contacts/
ajaxshoweditcontact'
end %>

and the edit page also has this for the cancel:

_ajaxshoweditcontact.rhtml.
<%= button_to_function 'Cancel' do |page|
  page[:showcontact].replace_html :partial => '/contacts/
ajaxshowcontact'
end %>

When I am trying to display the contact this:
_ajaxshowcontact.rhtml.
<%# = link_to_function 'Edit Contact' do |page|
  page[:showcontact].replace_html :partial => '/contacts/
ajaxshoweditcontact'
end %>

is one of 2 options.
Rails is saying that it cannot allocate memory for this and it will
not even display the initial page that has the 'edit' link. Is it
trying to render all of the partials before the button or link is even
clicked?

I am trying to cut down on the ajax calls that are not neccesary.

ok maybe not enough detail.

When a user selects a person from a drop down selection it shows the
user below with 2 options, to edit the user or delete the user

<%= link_to_function 'Edit Contact' do |page|
   page[:showcontact].replace_html :partial => '/contacts/
ajaxshoweditcontact'
end %>

Inside the ajaxshoweditcontact there is this link top cancel the edit:

<%= button_to_function 'Cancel' do |page|
  page[:showcontact].replace_html :partial => '/contacts/
ajaxshowcontact'
end %>

Is it generating the partials for both links when I go to the show
page above?

ok maybe not enough detail.

When a user selects a person from a drop down selection it shows the
user below with 2 options, to edit the user or delete the user

<%= link_to_function 'Edit Contact' do |page|
page[:showcontact].replace_html :partial => '/contacts/
ajaxshoweditcontact'
end %>

Inside the ajaxshoweditcontact there is this link top cancel the edit:

<%= button_to_function 'Cancel' do |page|
page[:showcontact].replace_html :partial => '/contacts/
ajaxshowcontact'
end %>

Is it generating the partials for both links when I go to the show
page above?

yes - it is generating the partials and including them in the page -
if you look at the source of the page you'd see something like

Element.update('showcontact', 'long html string here')

Fred

It is all ajax and it never complete out. It looks like it is in a loop generating each partial over and over again. when it finally times out it says it cannot allocate memory. Is there any way around this so I do not have to make ajax calls for those 2 actions as it is not really necessary?