【发布时间】:2015-03-06 12:06:13
【问题描述】:
我正在尝试创建一个在集合选择选项上提交的表单,例如当我从下拉列表中选择一个值时,它应该发布,下面发布的内容不起作用,
<%= form_tag edit_zone_management_path, :method => 'get', :id => "bar" do %>
<%= collection_select :dropdown, :id, Server.where(:id => @arr),:id, :server_name, :prompt => true, :selected => @sid %>
<%end%>
有人可以指出这里缺少什么吗?
加法
有一些coffeescript绑定到这个集合选择。
$ ->
$("#dropdown_id").live "change", -> // id of the collection_select
index = this.selectedIndex
uid = window.location.pathname.split("/")
if index == 0
index += 1
response = "{ \"key\": { \"value\" : #{index} } }"
#window.location.replace(uid[0]+ "/" + uid[1] + "/" + uid[2] + "/" + uid[3] + "/" +uid[4])
$.ajax({
type: 'POST',
url: '/configuration/zone_management/updategrid/',
data: response,
contentType: "application/json",
});
【问题讨论】:
-
您能否再描述一下您所说的“不工作”是什么意思?它会抛出任何错误吗?将您重定向到不同的操作?
-
您能否也提供您的config/routes.rb?
-
当我选择一个选项时没有任何反应,而且我还没有为此操作定义任何路线。我应该添加“get 'edit''' 路线吗?
-
还有一个问题 - 你有与此表单相关的 JavaScript 吗?
-
是的!以前我通过 javascript 执行此操作,该脚本仍在选择选项时触发。
标签: ruby-on-rails ruby