Rails观察Field Escape排序

时间:2011-01-05 06:40:36

标签: jquery ruby-on-rails ajax

我目前在rails网页中有一个使用AJAX搜索特定用户名的观察字段。但是我无法正确获取转义序列。 这是Rails代码:

%= observe_field "new_member_search",
      :url => {:controller => :user, :action => :search},
      :frequency => 0.5,
      :update => 'ProjectMemberNew',
      :with => :username
  %>

这是控制器

def search #search for user, use in 'Project Add Member'
name = params['username']
limit = params['limit'] || 21
users = unless name.blank?
  User.find_by_sql(
    ["select id,icon,login,realname,email from users where 
                      #{User.verified_users} and login like  ? limit ?","%#{name}%" ,limit])
else
  []
end
render(:partial => 'search_hit_member',
  :locals => {:users => users},
  :layout => false)

这会生成以下Javascript

<script type="text/javascript">
//<![CDATA[
jQuery('#new_member_search').delayedObserver(0.5, function(element, value) {jQuery.ajax({data:'username=' + value, success:function(request){jQuery('#ProjectMemberNew').html(request);}, type:'post', url:'/of/user/search'})})
//]]>
</script>

非常奇怪它应该不起作用。我刚刚从Prototype切换到JQUERY。

谢谢,

1 个答案:

答案 0 :(得分:0)

原来这不是逃避排序问题。你必须首先初始化jquery,然后jquery-ui然后jrails。如果它不在那个订单中,则delayedObserver将不会初始化。确实很奇怪。 https://github.com/aaronchi/jrails/issues#issue/6