【问题标题】:Making a form on collection select - Rails在集合选择上制作表单 - Rails
【发布时间】: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


【解决方案1】:

您的$.ajax 调用似乎缺少任何处理程序,请尝试添加一些:

$.ajax({
  type: 'POST'
  url: '/configuration/zone_management/updategrid/'
  data: response
  contentType: "application/json"
  success: (response) ->
    console.log response
    alert "Success fired"
  error: (response) ->
    console.log response
    alert "Error fired"
 })

这只是示例,因此请相应地调整您的处理程序!

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-21
    相关资源
    最近更新 更多