ruby on rails 实现自动完成功能

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

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

然后在view视图中加入 <%= text_field_with_auto_complete :role,:title %> ,其中,role是类名,title是字段名。

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

你可能感兴趣的:(Google,Ruby,Rails)