我在設置這個gem時遇到了很多麻煩。我剛剛添加了寶石 - 首先,它真的與Rails 4兼容嗎? (因爲這就是我使用的)Ruby on Rails - rails3-jquery-autocomplete
如果是這樣,我不知道我在做什麼錯。我有UserOrganizations
和Organizations
模型。 UserOrganizations存儲用戶和組織之間的關係 - 因此它是組織。
我希望人們可以通過組織的:name
進行搜索,以便將其添加爲與其用戶帳戶的關係。在user_organizations_controller.rb:
autocomplete :organization, :name, full: true
的routes.rb:
resources :user_organizations do
get :autocomplete_organization_name, on: :collection
end
然後,繼續在本教程provided here,我加入UserOrganization的_form.html.erb如下:
<%= f.autocomplete_field :organization_name,
autocomplete_organization_name_user_organizations_path %>
然後返回:
undefined method `organization_name' for #<UserOrganization:0x6846f48>
在視圖中,我實際上是否需要放入:organization
? :name
?如果不是,我不知道我需要做什麼改變,我非常仔細地跟着教程,儘管這不是一個實際的屬性名稱,但它放在:brand_name
中。我安裝了jquery-rails和jquery-ui-rails,autocomplete-rails.js與其他腳本文件一起列出。謝謝你的幫助。當然,這是在重複重新啓動服務器之後。