Hi, I start to use JQuery with Rails: I should make a simple text link to call in Ajax (by GET) an action in controller. link_to_remote is a Prototype method, I would use just a javascript framework (JQuery). Is it possible to use "link_to" to make ajax call ? (I didn''t have succeed ) What I should use instead of link_to_remote ? Thank you ! Alessandro -- Posted via http://www.ruby-forum.com/.
On Tue, Oct 20, 2009 at 6:05 PM, Ale Ds <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > I start to use JQuery with Rails: > I should make a simple text link to call in Ajax (by GET) an action in > controller. > > link_to_remote is a Prototype method, I would use just a javascript > framework (JQuery).OK, Prototype is a Javascript framework and happens to be the default for Rails, but link_to_remote is a Rails method. If you''re gonna use jQuery on your Rails application, you better install the jrails plugin[1] which will give you the proper replacements for those helper methods.> > Is it possible to use "link_to" to make ajax call ?Yes, it is.> (I didn''t have succeed ) > What I should use instead of link_to_remote ?You could use any click handler function and perform an $.ajax or $.get or $.post call in that handler, jQuery docs has the right information for you. [1]http://wiki.github.com/aaronchi/jrails -- Leonardo Mateo. There''s no place like ~
There are a number of great railscasts that cover this topic. http://railscasts.com/episodes?search=jquery It is possible to use the jrails plugin. It is also possible to code your application using unobtrusive javascript, which may be another good topic to study. That way you remove a lot of the clutter from your views. sax On Oct 20, 9:23 am, Leonardo Mateo <leonardoma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Oct 20, 2009 at 6:05 PM, Ale Ds<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Hi, > > I start to use JQuery with Rails: > > I should make a simple text link to call in Ajax (by GET) an action in > > controller. > > > link_to_remote is a Prototype method, I would use just a javascript > > framework (JQuery). > > OK, Prototype is a Javascript framework and happens to be the default > for Rails, but link_to_remote is a Rails method. > If you''re gonna use jQuery on your Rails application, you better > install the jrails plugin[1] which will give you the proper > replacements for those helper methods. > > > > > Is it possible to use "link_to" to make ajax call ? > > Yes, it is. > > > (I didn''t have succeed ) > > What I should use instead of link_to_remote ? > > You could use any click handler function and perform an $.ajax or > $.get or $.post call in that handler, jQuery docs has the right > information for you. > > [1]http://wiki.github.com/aaronchi/jrails > > -- > Leonardo Mateo. > There''s no place like ~
Leonardo Mateo wrote:> On Tue, Oct 20, 2009 at 6:05 PM, Ale Ds > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Hi, >> I start to use JQuery with Rails: >> I should make a simple text link to call in Ajax (by GET) an action in >> controller. >> >> link_to_remote is a Prototype method, I would use just a javascript >> framework (JQuery). > OK, Prototype is a Javascript framework and happens to be the default > for Rails, but link_to_remote is a Rails method. > If you''re gonna use jQuery on your Rails application, you better > install the jrails plugin[1] which will give you the proper > replacements for those helper methods. > >> >> Is it possible to use "link_to" to make ajax call ? > Yes, it is.yes, you are right. I have resolved in this way: in the view <%= link_to(''Update table'', users_path(@user) ,:id => ''id_update_link'') %> and in application.js $(''#id_update_link'').click(function(){ $.get($(this).attr("href"), $(this).serialize(), null, "script"); return false; }); thank you, Alessandro -- Posted via http://www.ruby-forum.com/.