开发者

help with a rails ajax button_to :remote

开发者 https://www.devze.com 2023-02-06 07:13 出处:网络
Hi Im trying to make a button_开发者_如何学Pythonto :remote with Rails3, which when onclick it will fetech some content and display success alert when ajax did a round trip back with status 200.

Hi Im trying to make a button_开发者_如何学Pythonto :remote with Rails3, which when onclick it will fetech some content and display success alert when ajax did a round trip back with status 200.

my code now =

<%= button_to 'helloworld', '/ccs', :remote => true ,:method=>'get', :disable_with => 'loading', :confirm => "are u sure?", :success =>"alert('lol');" , :failure=>"alert('omg');"%>

It dose send another HTTP request when button clicked but just not having any action on success or failure.

What's wrong with it anyone?


Rails 3 no longer has support for prototype helpers and their callbacks, such as :success and :failure. Read more on this page, particularly sections 3 and 4:

http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/

As you can see, you'll have to bind those callbacks manually (the page above uses jQuery), but you won't be able to do so inline.

Alternatively, button_to_remote, which will do exactly what you want, is now available as a plugin:

http://github.com/rails/prototype_legacy_helper

0

精彩评论

暂无评论...
验证码 换一张
取 消