【问题标题】:what is the name of my form我的表格叫什么名字
【发布时间】:2012-01-24 15:49:39
【问题描述】:

我的最终目标是创建一个复选框,后,选中后,请检查表单中的所有复选框。并在从选中变为未选中时取消选中它们。我见过的所有帖子(this onethis one)都需要使用我的表单名称。我的表格名称是什么?这是我的全部观点:

<%= render 'admin/distributions/head' %>
<% title 'Workflow' %>


<%= form_for @search, :url => url_for(:controller => params[:controller], :action => params[:action]), :html => {id => "distribution_workflow",:method => :get} do |f| %>

  <div class="opportunity-block yellow">

    <div class="form-block mrl mbm">
      <%= f.label :created_at_gt, "Created at >" %>
      <%= f.text_field :created_at_gt, :class => "js-db-date-picker" %>
    </div>

    <div class="form-block mrl mbm">
      <%= f.label :created_at_lte, "Created at <=" %>
      <%= f.text_field :created_at_lte, :class => "js-db-date-picker" %>
    </div>

    <div class="form-block mrl mbm mtm">
      <%= f.label :status_equal, "Status" %>
      <%= f.select :status_equal, Distribution.select(:status).group(:status).order(:status).map { |d| [d.status] }, :include_blank => " " %>
    </div>

    <div class="clear"></div>
    <%= submit_tag 'Apply Filter', :class => "input-button dark unit-right mrl" %>
    <div class="clear"></div>
  </div>
<% end  %>


<%= form_tag edit_multiple_admin_distributions_workflows_path do %>
<%= submit_tag "Edit Selected" %>
  <table class="standard-grid">
    <tr>
      <th class="first">
      </th> 
      <th>ID</th>
      <th>Customer</th>
      <th>Resume URL</th>
      <th>Partner</th>
      <th>Status</th>
      <th>Assigned To</th>
      <th>Comments</th>
      <th></th>
    </tr>
    <% @report.each do |distribution| %>
      <tr>
        <td><%= check_box_tag "distribution_ids[]", distribution.id %></td>
        <td>
          <%= distribution.owner.id %>
        </td>
        <td>
          <%=link_to distribution.owner.full_name, "mailto:#{distribution.owner.email}" %>
        </td>
        <td>
          <a href=<% UrlService.download_blob_url(distribution.resume) %>>Resume URL</a>
        </td>
        <td>
          <%=link_to distribution.matching_profile.partner.title,  "mailto:#{distribution.matching_profile.partner.email}" %>
        </td>
        <td>
          <%= distribution.status %>
        </td>
        <td>
          <%= distribution.assignee_id %>
        </td>
        <td>
          <%= distribution.comments %>
        </td>
      </tr>
    <% end %>
  </table>
<% end %>

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 forms checkbox


    【解决方案1】:

    您在这里有两个表单标签,但您要查找的是表单的 ID,而不是 NAME。

    您发布的链接所引用的 jQuery 如下所示:

    $("#my_form")...
    

    #表示ID,所以如果你的表单的ID是:

    <form id="some_id_here">
    

    你会使用:

    $("#some_id_here")...
    

    为了找到它,您可以右键单击页面上的元素(当您查看实际页面时) - 然后单击“检查元素”。这是在 Chrome/Firefox/Safari 中。我不记得它在 IE 中的确切名称,但你明白了。

    【讨论】:

    • 这带来了两个问题。 1.) 跨环境(本地、开发、登台、生产)的表单 ID 是否始终相同?和 2.) 为什么我在 chrome 中看不到这个??
    【解决方案2】:

    Rails 中不会自动设置表单名称,但是您可以通过传递 html_options 为表单设置名称。

    Eg.: <%= form_for(@obj, :html => { :name => "test" }) do |f| %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多