帮助一个轨道ajax button_to:远程

时间:2011-01-25 03:22:17

标签: ruby-on-rails-3 prototype

嗨我正在尝试使用Rails3创建一个button_to:remote,当ajax回复状态为200时,onclick会显示一些内容并显示成功提示。

我的代码现在=

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

当点击按钮时它会发送另一个HTTP请求,但是没有对成功或失败采取任何行动。

有人怎么了?

1 个答案:

答案 0 :(得分:3)

Rails 3不再支持原型助手及其回调,例如:成功和失败。 在此页面上阅读更多内容,尤其是第3和第4部分:

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

如您所见,您必须手动绑定这些回调(上面的页面使用jQuery),但您无法内联。

或者,button_to_remote,它将完全按照您的意愿行事,现在可以作为插件使用:

http://github.com/rails/prototype_legacy_helper