Hi all, I have a complex link_remote_to link I need to generate often. I want to DRY up my view and create a helper that generates this link_remote_to for me. Is there a way my helper can output the link_remote_to javascript? Thanks STijn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 24, 2007, at 5:22 AM, Tarscher wrote:> > Hi all, > > I have a complex link_remote_to link I need to generate often. I want > to DRY up my view and create a helper that generates this > link_remote_to for me. > > Is there a way my helper can output the link_remote_to javascript?I haven''t actually tried this, but I''m thinking it should work. Since link_to_remote is just a helper, I don''t see why you couldn''t create a helper that calls it. Something like: def my_link_to_remote(<your args>) link_to_remote <blah blah blah> end It wouldn''t be hard to find out. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nope, tried that but that doesn''t work. I''ll have to put it in a partial I think. Regards, Stijn On 24 dec, 14:43, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 24, 2007, at 5:22 AM,Tarscherwrote: > > > > > Hi all, > > > I have a complex link_remote_to link I need to generate often. I want > > to DRY up my view and create a helper that generates this > > link_remote_to for me. > > > Is there a way my helper can output the link_remote_to javascript? > > I haven''t actually tried this, but I''m thinking it should work. Since > link_to_remote is just a helper, I don''t see why you couldn''t create > a helper that calls it. Something like: > > def my_link_to_remote(<your args>) > link_to_remote <blah blah blah> > end > > It wouldn''t be hard to find out. > > Peace, > Phillip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 24, 2007, at 8:46 AM, Tarscher wrote:> > nope, tried that but that doesn''t work. >You might want to do some more research then. I just did a simple test like this: In a view template <%= my_link_to_remote ''Click here'', ''wgg'', ''link_to_test'', ''link_to_target'' %> <div id="link_to_target"> </div> in the helper def my_link_to_remote(label, controller, action, update) link_to_remote label, :url => {:controller => controller, :action => action}, :update => update end and in the controller def link_to_test if request.xhr? render :text => Time.now.to_s end end And it worked as I expected it to. You should be able to pass in whatever args you need and call link_to_remote to build the link for you. Unless your need is extremely complex. Maybe you can post some example of what you''re trying to do? Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 got it to work. The link_to_remote indeed just works in the helper. I have an additional problem though: I want to output 2 link_to_remotes to my view with the helper: I have something like if(condition1) link_to_remote1 link_to_remote2 else link_to_remote1 link_to_remote2 end It always just outputs 1 linkto_remote (the second). I''m I doing something wrong? regards, Stijn On 24 dec 2007, 16:34, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 24, 2007, at 8:46 AM, Tarscher wrote: > > > > > nope, tried that but that doesn''t work. > > You might want to do some more research then. I just did a simple > test like this: > > In a view template > > <%= my_link_to_remote ''Click here'', ''wgg'', ''link_to_test'', > ''link_to_target'' %> > <div id="link_to_target"> > </div> > > in thehelper > > def my_link_to_remote(label, controller, action, update) > link_to_remote label, :url => {:controller => controller, :action => > action}, :update => update > end > > and in the controller > > def link_to_test > if request.xhr? > render :text => Time.now.to_s > end > end > > And it worked as I expected it to. You should be able to pass in > whatever args you need and call link_to_remote to build the link for > you. Unless your need is extremely complex. Maybe you can post some > example of what you''re trying to do? > > Peace, > Phillip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 10, 2008, at 10:46 AM, Tarscher wrote:> > I got it to work. The link_to_remote indeed just works in the helper. > > I have an additional problem though: > I want to output 2 link_to_remotes to my view with the helper: > > I have something like > if(condition1) > link_to_remote1 > link_to_remote2 > else > link_to_remote1 > link_to_remote2 > end > > It always just outputs 1 linkto_remote (the second). I''m I doing > something wrong? >You are experiencing one of the niceties of Ruby: the last "thing" in a method gets returned. You will want to capture the output of both calls to link_to_remote and return them together. I have *not* tried this, but somethiing like this should work link_string = '''' link_string = link_to_remote blahblahblah link_string += <something to separate the links, maybe a <br /> ?> link_string += link_to_remote blahblahblah return link_to_string Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---