I have a number of links to external webpages and want to execute some Ruby code whenever one of them is clicked, e.g. log which URL was clicked how many times. To the user the links should behave as usual though. I''ve been playing around with link_to_remote but couldn''t find a solution. Any suggestions? Max --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
First of all link_to_remote is for sending AJAX requests to the server not for sending the user to a remote site. What you need to do is have your links calls an action in your controller. The action will log the click by updating your database, then you can redirect the user to the remote site (probably in a new browser window by using target = "_blank"). In any case your application will need to initially receive the request so it can handle the processing you want. The only affect your user may notice is the redirect, but that''s pretty common on the web anyway. Max wrote:> I have a number of links to external webpages and want to execute some > Ruby code whenever one of them is clicked, e.g. log which URL was > clicked how many times. To the user the links should behave as usual > though. > > I''ve been playing around with link_to_remote but couldn''t find a > solution. > > Any suggestions? > > Max--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> First of all link_to_remote is for sending AJAX requests to the server > not for sending the user to a remote site.I know, I was trying to have a normal link and let it execute some ruby code onclick. So I tried a few things with link_to and link_to_remote. But this seems to be impossible, right?> What you need to do is have your links calls an action in your > controller. The action will log the click by updating your database, > then you can redirect the user to the remote site (probably in a new > browser window by using target = "_blank"). In any case your > application will need to initially receive the request so it can > handle the processing you want. The only affect your user may notice > is the redirect, but that''s pretty common on the web anyway.I was trying to avoid redirection, but if that''s the only solution, ok. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---