---
title: "ruby on rails 实现自动完成功能"
author: "PBFox"
date: "2007-09-25T08:28:00Z"
tags: []
slug: "ruby-on-rails"
draft: false
lastmod: "2007-09-25T08:28:00Z"
id: 479285
url: "https://developerwork.iteye.com/blog/479285"
---

在网上看到了好多类似google搜索时的自动完成功能。 便搜索看了一下，很简单：

我用了一个脚手架：generators scaffold Role role list new edit.

然后在view视图中加入 &lt;%= text\_field\_with\_auto\_complete :role,:title %&gt; ,其中，role是类名，title是字段名。

再在对应的控制器中加入 auto\_complete\_for :role,:title，这样就实现了自动完成的功能，很简单。