rails,prototype和:afterFinish回调问题

时间:2010-11-06 23:42:39

标签: ruby-on-rails prototype

为什么这样做

<script type="text/javascript">
    var mycallback = function() {
      $('user_session_username').focus();
     };
</script>

page.visual_effect :appear, 'user-response', :afterFinish => "mycallback"

以下两个陈述都不起作用

page.visual_effect :appear, 'user-response', :afterFinish => "$('user_session_username').focus()" 

page.visual_effect :appear, 'user-response', :afterFinish => "$('user_session_username').focus" 

1 个答案:

答案 0 :(得分:1)

这是否有效:

page.visual_effect :appear, 'user-response', :afterFinish => "function(){$('user_session_username').focus()}"

注意: link_to_function适用于Rails 2.x但不适用于Rails 3.x. More info on this