Javascript 如何以特定的方式提交表格?

Javascript 如何以特定的方式提交表格?,javascript,jquery,ruby-on-rails,forms,Javascript,Jquery,Ruby On Rails,Forms,我需要从我的控制器向特定方法提交表单。 我该怎么做? 我的表单如下所示: <%= form_tag({update_holidays_path, method: 'post'},{name: "exchange", id: "exchange"}) do %> <table width="auto" border="0"> <thead> <th scope="col">Selected</th> <th w

我需要从我的控制器向特定方法提交表单。 我该怎么做? 我的表单如下所示:

<%= form_tag({update_holidays_path, method: 'post'},{name: "exchange", id: "exchange"}) do %>
<table width="auto" border="0">
  <thead>
    <th  scope="col">Selected</th>
    <th width="50" scope="col">&nbsp;</th>
    <th  scope="col">Holidays</th>
  </thead>  
  <tbody>
  <tr>
  <td>  
    <% holidays_array = @group.holidays.all.map { |holiday| [holiday.name, holiday.id] } %>
    <%= select(:holiday_id, :name, options_for_select(holidays_array),{}, 
    {:multiple => true, :style => "width: 300px; background-color: #9FE", :width => "300", :size => 20, :id=>"left" }  ) %>
  </td>
  <td align="center">
      <%= link_to "<<", {anchor: "", remote: true}, {id: "toleft" ,  w_command: "add_holiday", w_auth: form_authenticity_token , w_controller: "groups",  w_id: @group.id} %>
      <br /><br />
      <%= link_to ">>", {anchor: "", remote: true}, {id: "toright" , w_command: "rem_holiday", w_auth: form_authenticity_token , w_controller: "groups",  w_id: @group.id} %>
  </td>    
  <td>
    <% holidays_array = Holiday.all.map { |holiday| [holiday.name, holiday.id] } %>
    <%= select(:holiday_id, :name,  options_for_select(holidays_array),{}, 
    { :multiple => true, :style => "width: 300px; background-color: #F99", :width => "300", :size => 20, :id=>"right" } ) %>
  </td>
  </tr>
  </tbody>
</table>
我想用以下javascript提交我的左选择:

var save=function()
{
alert("0");
var left = document.getElementById("left");
alert(left);
var result = document.exchange;
alert(result);
result= ""
alert("3");
for(i=0;i<right.length;i++)
    {       
    result.value=result.value+","+left.options[i].value; //right.options[i].selected = true;
    alert("4,"+i+"    "+result.value);
    }
alert("5");          
result.submit();
}

有没有办法做到这一点?

将更新路径更改为要调用的控制器和操作的路径

打开终端。转到rails\u app\u根目录并执行rake路由 这将为您提供所有可用路径的列表

例如:

 cases GET    /cases(.:format)                                    cases#index
这里casesindex表示案例是控制器名称,索引是方法 所以,当您编写cases\u path时,它将生成此控制器和操作的路径

因此,在rake routes列表中找到控制器和操作的匹配路由,然后选择最左边的文本并在其后面追加路径,就像我在上面的示例中所示,然后用这个新找到的路径替换下面一行中的更新路径

编辑

如果路径不在rake routes列表中,则需要将此路径添加到routes.rb文件中