我讓用戶從自動填充字段中選擇類型。該字段位於配置文件的編輯視圖中,因此我在配置文件模型中有accepts_nested_attributes_for :genres
。另外,流派和個人資料有一個has_and_belongs_to_many
彼此關聯。我的問題是,你如何選擇用戶選擇的類型併爲其用戶配置文件設置它們?我需要什麼樣的控制器代碼?代碼會放入配置文件或流派控制器中嗎?如何設置在自動填充字段中選擇的元素
我正在使用它來自動完成:http://loopj.com/jquery-tokeninput/我已經預先填充了流派表並將腳本連接到文本字段。當用戶輸入時,自動完成功能會成功顯示建議。現在我想用選定的流派更新數據庫。此數據庫是流派和配置文件之間的連接表。我如何以及在哪裏做這件事?總結一下,當我點擊配置文件編輯視圖中的按鈕時,我想保存配置文件ID和選擇到連接表中的流派的ID之間的關聯。現在,我得到這個錯誤:
ActiveRecord::UnknownAttributeError in ProfilesController#update
unknown attribute: genre
Rails.root: /rubyprograms/dreamstill
app/controllers/profiles_controller.rb:18:in `update'
app/controllers/profiles_controller.rb:17:in `update'
,這裏是我的個人資料編輯觀點:
<%= form_for(:profile, @profile, :url => {:controller => "profiles", :action => "update"}, :html => { :multipart => true, :method => :put }) do |f| %>
...
<%= f.fields_for :genre do |g| %>
<div class="field">
<%= g.label :name, "Genres" %><br />
<%= g.text_field :name, :id => 'genre_field' %>
</div>
<% end %>
...
<div class="action">
<%= f.submit :profile, :value => "Update Profile" %>
</div>
<% end %>
的ID的隱藏的文本字段? 看看這個https://github.com/crowdint/rails3-jquery-autocomplete – Pravin 2011-03-30 04:37:47
我使用這個自動完成:http://loopj.com/jquery-tokeninput/我已經預先填充數據庫和將腳本連接到文本字段。現在我想用選定的流派更新數據庫。 – 2011-03-30 04:45:17