0
編輯:尋找這樣的:http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery(如果這個工程,我會回答我的問題)軌formtastic的habtm進出
我開始創建一個進出類型的habtm(有許多屬於許多)通過formtastic形成。然而,我希望它對用戶更靈活,這意味着如果您在一側選擇名稱,您可以單擊立即移動它的按鈕(單擊ajax)或提交表單後
(I'使用間formtastic這一點,但它並沒有給任何人以實例)
什麼我掙扎是JavaScript,進出按鈕..
比較借鑑
class Comparison < ActiveRecord::Base
has_and_belongs_to_many :devices
end
Devi CES型號
class Device < ActiveRecord::Base
has_and_belongs_to_many :comparisons
end
比較控制器
def edit
@comparison = Comparison.find(params[:id])
@devices = Device.find(:all, :select => 'id, device_name', :order => 'device_name')
@devices_selected = @comparison.devices.find(:all, :order => 'device_name', :conditions => ["id IN (?)", @devices])
@devices_not_selected = Device.find(:all, :order => 'device_name', :conditions => ["id NOT IN (?)", @devices_selected])
end
比較,編輯,查看
<% semantic_form_for @comparison do |f| %>
<% f.inputs do %>
<%= f.input :comparison_name %>
<%= f.input :description %>
<h3>
Select Devices
</h3>
<% f.inputs :class => 'inline_fields' do %>
<%= f.input :devices,
:collection => @devices_not_selected,
:label_method => :device_name,
:label => 'Add Devices',
:input_html => { :size => 20 },
:include_blank => false,
:hint => 'Select devices from this list to compare to the parent device' %>
<%= f.input :devices,
:collection => @devices_selected,
:label_method => :device_name,
:label => 'Remove Devices',
:input_html => { :size => 20 },
:include_blank => false,
:hint => 'Deselect devices from this list to take them off the comparison' %>
<% end %>
<% end %>
<%= f.buttons %>
<% end %>