Jquery 在rails中不提交的按钮,以及在控制器中处理f.select的按钮

Jquery 在rails中不提交的按钮,以及在控制器中处理f.select的按钮,jquery,ruby-on-rails,ruby,Jquery,Ruby On Rails,Ruby,更新:我忘记了type=按钮,这已经更新了。我的按钮仍然失败,我想这是因为当我测试时,我使用了select_标记,然后在试图让它在控制器端工作时,我将其切换为f.select,在一个for的表单中,在这种情况下,我的javascript无法正常工作。我猜是因为f.select使对象有所不同。我现在的问题是,我应该为f.select使用一个form_还是select_标记?我不太确定两者的区别,我猜f的形式_。select给了我一些传递模型的自动性。如果我使用select_标记,我仍然可以使用控制

更新:我忘记了type=按钮,这已经更新了。我的按钮仍然失败,我想这是因为当我测试时,我使用了select_标记,然后在试图让它在控制器端工作时,我将其切换为f.select,在一个for的表单中,在这种情况下,我的javascript无法正常工作。我猜是因为f.select使对象有所不同。我现在的问题是,我应该为f.select使用一个form_还是select_标记?我不太确定两者的区别,我猜f的形式_。select给了我一些传递模型的自动性。如果我使用select_标记,我仍然可以使用控制器上的对象吗?我真的不知道在这两种情况下会出现什么样的参数映射。另外,如果f.select是首选方法,那么我将相应地调整javascript

var ready;
ready = function() {

            $('.add').on('click', function() {
                var options = $('select#group_providers option:selected').sort().clone();
                $('select#provider_locations').append(options);
            });
            $('.addAll').on('click', function() {
                var options = $('select#group_providers option').sort().clone();
                $('select#provider_locations').append(options);
            });
            $('.remove').on('click', function() {
                $('select#provider_locations option:selected').remove();
            });
            $('.removeAll').on('click', function() {
                $('select#provider_locations').empty();
            });

};

$(document).ready(ready);
$(document).on('page:load', ready);
我有一些java脚本处理两个多选择框

我要我的删除,删除所有不提交表格。他们似乎自然而然地做到了这一点。如果我在表单顶部省略了表单_,那么这些按钮将执行它们应该执行的java脚本。。。或者如果我使用我在博客上找到的代码:

http://www.whatibroke.com/?p=259

然后确保它没有提交,但是javascript也不能工作

其次,我还将它们作为select_标记,然后将它们移动到表单_下。如何处理返回到控制器中的左列中的数据真的让我很困惑,而且这个表单也是从控制器中的add_locations操作调用的。提交再次调用一个更新操作是合乎礼仪的,还是我想调用另一个操作来处理我认为可以传递到表单_中的数据?下面的代码让我很困惑,因为我这里的模型有很深的关联

<div class="container">
<div class="row">
  <%= form_for (@provider) do |f| %>
    <div class="col-md-4">
            <table>
              <tr>
                <th>            
                  <h3> <%= @provider.last_name %> , <%= @provider.first_name %> 's Locations</h3>
                </th>
              </tr>
              <tr>
                <td>          
                 <% if @provider.provider_locations.count >0 %>
                    <%= f.select "provider_locations", options_from_collection_for_select(@provider.provider_locations.map{|j| j.group_location}, :id , :dba), {}, {:multiple => elseb} %>
                  <% true %>
                    <%= f.select "provider_locations", "<option></option>".html_safe, :multiple => true, :style => "width: 300px" %>       
                  <% end %>
                </td>
              </tr>
              <tr>
                <td>          
                   <!-- <button class="remove">Remove</button>  -->
                   <%= submit_tag 'Remove it', :type => 'button', :class => 'remove' %>

                </td>
                <td>          
                  <!-- button class="removeAll">Remove All</button -->
                  <%= submit_tag 'Remove All', :type => 'button', :class => 'removeAll' %>
                </td>
              </tr>
            </table>         
    </div>
    <div class="col-md-4">
         <table>
              <tr>
                <th>            <!-- maybe some buttons here -->

                </th>
              </tr>                   
            </table>
     </div>
     <div class="col-md-4">
            <table>
              <tr>
                <th>            
                 <h3> All Group Locations </h3> <!-- might need a search here too -->
                </th>
              </tr>
              <tr>
                <td>          
                  <% if @group_locations.count >0 %>
                    <%= select_tag "group_providers", options_from_collection_for_select(GroupLocation.all, :id , :dba), :multiple => true %>
                  <% else %>
                    <%= select_tag "group_providers", "<option>Add new...</option>".html_safe, :multiple => true, :style => "width: 300px" %>       
                  <% end %>

                </td>
              </tr>
              <tr>
                <td>          
                    <button class="add">Add</button>

                </td>
                <td>          
                    <button class="addAll">Add All</button>
                </td>
              </tr>
            </table>        
    </div>
    <div class="actions">
      <%= f.submit %>
    </div>
  <% end %>
  </div>
</div>

对于按钮,只需使用a标记并将其样式设置为按钮,或者您可以显式地将按钮的类型设置为button,因为默认类型为submit,这将触发提交表单。谢谢。按钮仍然会失败,我想这是因为我的表单是_for,所以它找不到提供者_位置选择了。我猜形式_改变了一些东西,所以我把它添加到我的问题中。