Page.replace_html :template => 'index'

Hi

I have an index.rhtml which is the default view.

I have a form that is loaded/opened using rjs. If the info does not
save, I
have ajax error_messages_for that shows the user what is wrong.
This works nicely, however, if the info is correct and the records are
saved, I would like to present the index page again.

Ideally, I would just redirect_to :action => ‘index’ in my view, but the
call comes from a form_remote_for which does not like the redirect_to.

So, what I am trying to do at the moment is to

if saved
render (:update) do |page|
page.replace_html ‘content’, :template => ‘index’
end
else
render (:update) do |page|
page.replace_html ‘form’, :partial => ‘form’
end
end
where content div is the div that receives @content_for_layout.

I get rjs error html has no properties

Element.update(“content”,null);

Can anyone explain to me what is happening here, and/or how to fix it.

regards
Ivor

Hi,

Ivor P. wrote:

Ideally, I would just redirect_to :action => ‘index’ in
my view, but the call comes from a form_remote_for
which does not like the redirect_to.

You can use page.redirect_to … within your RJS.

hth,
Bill

add :update => “content” in your form_remote_for tag
eg.
<% form_remote_for(@object,:url => {:action => ‘update’},
:update => “content”) do |f| %>
<% end %>

and in your controller
if saved
render :template => ‘index’
else
render (:update) do |page|
page.replace_html ‘form’, :partial => ‘form’
end
end

its working.