I wondered if anyone can help me, I am trying to add some basic ajax to
my new project but I’ve run into a problem.
I have a RESTful ProductsController which uses pagination, I would like
to basically re-render the index template on susbequent ajax calls to
the index action. However the following doesn’t work
format.js do
render (:update) do |page|
page.replace_html ‘main’, :template => ‘index’
end
end
The response I receive is
Element.update(‘main’,null);
which has the effect of empty the contents of my ‘main’ div, which is
not very helpful. It seems the following works, but its not what I need.
I thought replace_html receives a :partial option, and not a :template
option that is unknown… I think the nil object happens because there
isn’t :partial element as argument.
I think you’re right Unforunately I need to re-render the whole
template (minus the layout) not just a partial. Without separating the
content of my template into a partial for the sake of making this work
(which feels very wrong) I can’t see a way around it.
Any ideas?
Eduardo Yáñez Parareda wrote:
I thought replace_html receives a :partial option, and not a :template
option that is unknown… I think the nil object happens because there
isn’t :partial element as argument.
I think you’re right Unforunately I need to re-render the whole
template (minus the layout) not just a partial. Without separating the
content of my template into a partial for the sake of making this work
(which feels very wrong) I can’t see a way around it.
This is quite disgusting but:
in your controller @content = render_to_string :template => ‘foo’
in your rjs file : page.replace_html ‘main’, @content