2008年10月29日星期三

在rails > 2.0中使用auto_complete

原来auto_complete在rails 2.0之后已经作为offical plug-in发布,难怪...

简单记下使用步骤
1. install
script/plugin install auto_complete

2. 直接在controller中加入

class CaseController <>
auto_complete_for :case, :name

view中加入
<%= text_field_with_auto_complete :case, :name %>


3. 基本完成,不过reload page之后发现会有ActionController::InvalidAuthenticityToken之类的error message. 原因是If a request comes in that doesn’t match the request forgery protection token for the current session then an ActionController::InvalidAuthenticityToken exception will be thrown. 参考这篇文档,可以绕开.

最冲动的办法就是:在application.rb中加入
self.allow_forgery_protection = false


没有评论: