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.
page.replace_html ''main'', :partial =>
''somepartial''
Any one have any ideas, do I just have the syntax wrong?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Aug 2008, at 08:34, Rob Lacey wrote:> > 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 However you don''t need to do this, eg link_to_remote ''click me'', :url => ..., :update => ''main'' Then in you action just do a bog standard render :template => ... Fred> 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. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Indeed it is disgusting, but sometimes that''s necessary to solve a
problem :(
However I''ve managed to solve it, typically it was easier than I
thought
format.js do
render :update do |page|
page.replace_html ''main'', :file =>
''products/index''
end
end
Yay for the Rails source.
> This is quite disgusting but:
> in your controller @content = render_to_string :template =>
''foo''
> in your rjs file : page.replace_html ''main'', @content
>
> However you don''t need to do this, eg
>
> link_to_remote ''click me'', :url => ..., :update =>
''main''
>
> Then in you action just do a bog standard render :template => ...
>
> Fred
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---