rubyonrailsin

A Ruby and Rails talk

Wednesday, March 17, 2010


Re: [Rails] Re: Link as a link AND as a function

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Quoting Michael Murillo <lists@ruby-forum.com>:
> Jeffrey L. Taylor wrote:
> > Quoting Michael Murillo <lists@ruby-forum.com>:
> > <%= link_to_function truncate(article.title, 60),
> > "clickThru('#{article.url}','#{article[:id]}', 'click')",
> > :title => article.feed.title, :href => article[:id] %>
> >
> >
> > function clickThru(url, id, verb) {
> > new Ajax.Request('/articles/'+id+'/'+verb,
> > {asynchronous:true, evalScripts:true, method:'get'});
> > window.open(url);
> > }
>
> Thank you Jeffrey. I played around with it a bit and was wondering how
> the function intends to post to the clicks database. Is it by using
> that "id" => "click"? Or does "click" in your example refer to a method
> in a controller?
>

Sorry for the slow reply. I have been at SxSW Interactive for the last 5
days.

This code is copied from my app, it will need some editing for your app.
Ajax.request() is in the Prototype Javascript library, it makes a request to
the server. The first parameter is the URL to call, the rest is copied from
the code generated by link_to_remote. evalScripts:true indicates Javascript
is expected in the reply and should be evaluated, method:'get' indicates to
make a HTTP GET request instead of the default POST. The action on the server
calls the model(s) to update the database.

HTH,
Jeffrey

--
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@googlegroups.com.
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.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive