【问题标题】:rails formtastic habtm in and outrails formtastic habtm 进出
【发布时间】:2010-07-30 18:23:32
【问题描述】:

编辑:寻找这个:http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery(如果可行,我会回答我自己的问题)

我已经开始通过formtastic创建一个进出型habtm(有很多和属于很多)形式。但是我希望它对用户更加灵活,这意味着如果您在一侧选择一个名称,您可以单击一个立即移动它的按钮(单击时 ajax)或在提交表单后

(我使用的是formtastic,但在任何人的例子中都不需要)

我正在苦苦挣扎的是 javascript,输入和输出按钮..

比较模型

class Comparison < ActiveRecord::Base
    has_and_belongs_to_many :devices
end

设备型号

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 %>

【问题讨论】:

    标签: ruby-on-rails has-and-belongs-to-many formtastic


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多