On 9/5/07, chirag <patelc75-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
wrote:>
> I have the following code that will be repeated many times in a
> single .rthml page.
>
> <%=link_to_remote("Test AJAX",
> :update => ''chart'',
> :url => url_for(:controller => ''chart'', :action
=>
> ''linear_graph''),
> :loading => "Element.show(''loading''); ",
> :complete => "Element.hide(''loading'')",
> :before => "this.parentNode.className =
''myclass'';") %>
>
> What is the best way to DRY this up so
> the :loading, :complete:, :before: and :update callbacks are reused? I
> want to avoid changing all instances of this call when I update the
> code. The only parameter that will change is :url
I use something like the following:
in application_helper.rb:
def showing_progress(opts={}, hide_div = nil)
opts.merge :loading => update_page{|p| p[hide_div].hide if
hide_div; p[:progress].visual_effect(:appear, :duration => 0.5); },
:complete => update_page{|p| p[:progress].hide; p[hide_div].show
if hide_div; }
end
in my view.rhtml:
<%= link_to_remote(h(email.subject), showing_progress({:url =>
{:action => ''display_email'', :id => email}},
''email_content'')) %>
Adam
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---