根据rails中的用户选择获取记录

时间:2013-11-06 13:39:54

标签: javascript ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2

我有一个带有category_id和subcategory_id属性的着装模型,我想这样做,当用户从collection_select中选择一个类别类型时,表单会以一个复选框的形式更新该类别的子类别用户检查他需要的子类别,我可以通过$('#dress_category_id')来检测选择何时被更改。更改以及通过$('#dress_category_id:selected')选择了哪个类别类型.text()但是我不知道,我的搜索时间是徒劳的,如何用子类别模型更新其他表单字段。

这是我的表单代码:

<div id="" class="modal-form no-shadow eighty-margin-top">
  <div class="modal-header">
  </div>
  <div class="form-box">
    <header class="ui-min-header">
      <h3 class="letter_pressed light_header ">New Design</h3>
    </header>
    <div class="form-body  row-fluid" style="margin-top: 20px;">
      <%= form_for( @dress, :html => {class: "form-horizontal", role:"form" }) do |f| %>
          <%= render "error_messages", target: @dress %>

          <div class="form-group" id="avatar">
            <%= f.label :category, class: "col-lg-3 control-label" %>
            <div class="col-lg-9">
              <%= f.collection_select :category, Category.all, :id, :name, {:prompt=> "Select a category"}, {class: "form-control input-lg"} %>
            </div>
          </div>
            </div>
          </div>
子类别在这里 - &gt;
          <div class="form-group">
            <%= f.label :name, class: "col-lg-3 control-label" %>
            <div class="col-lg-9">
              <%= f.text_field :name, placeholder: "Name of your design", class: "form-control"  %>
            </div>
          </div>

          <div class="form-group">
            <%= f.label :keywords, class: "col-lg-3 control-label" %>
            <div class="col-lg-9">
              <%= f.text_field :keywords, class: "form-control"  %>
            </div>
          </div>

          <div class="form-group">
            <%= f.label :description, class: "col-lg-3 control-label" %>
            <div class="col-lg-9">
              <%= f.text_field :description, placeholder: "About your design", class: "form-control"  %>
            </div>
          </div>
          <div class="form-group">
            <div class="col-lg-offset-3 col-lg-9">
              <button type="submit" class="btn btn-warning">Continue</button><br/>
            </div>
          </div>
      <% end %>

    </div>

  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以查看jQuery Cascading Dropdown Plugin。要么直接使用它,要么检查它是如何在那里完成的。