Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何将隐藏表单放入表中?_Html_Ruby On Rails_Ruby - Fatal编程技术网

Html 如何将隐藏表单放入表中?

Html 如何将隐藏表单放入表中?,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,我不熟悉HTML和RoR。我试着在一张表的旁边有一个按钮来提交一个隐藏的表单。但由于某些原因,按钮不会显示在生成的HTML中 <table class="centerBox"> <h3>Search Results:</h3> <thead> <tr> <th>Name</th> <th>Code</th> <th>Subject_id<

我不熟悉HTML和RoR。我试着在一张表的旁边有一个按钮来提交一个隐藏的表单。但由于某些原因,按钮不会显示在生成的HTML中

<table class="centerBox">
  <h3>Search Results:</h3>
  <thead>
  <tr>
    <th>Name</th>
    <th>Code</th>
    <th>Subject_id</th>
  </tr>
  </thead>

  <tbody>
  <% @searchResults.each do |searchResult| %>
    <tr>
      <td><%= searchResult.name %></td>
      <td><%= searchResult.code %></td>
      <td><%= searchResult.subject_id %></td>
      <td>
        <% form_for(:enrollment, url: enroll_path) do |f| %>
          <div class="actions">
            <%= f.hidden_field(:enrollment, :course_name => searchResult.name)%>
            <%= f.hidden_field(:enrollment, :user_id => current_user) %>
            <%= f.submit "Enroll"%>
          </div>
        <% end %>
      </td>
    </tr>
  <% end %>
  </tbody>
</table>

搜索结果:
名称
代码
受试者id
searchResult.name)%%>
当前用户)%>
生成的HTML:

<tr>
      <td>Independent Study</td>
      <td>AAAS 98B</td>
      <td>1161-100</td>
      <td>
      </td>
</tr>

独立学习
AAAS 98B
1161-100
在网页上:

对于erb代码,要打印您调用的方法的输出,您需要对标记使用=,就像您对字段和提交按钮所做的那样

<%= form_for(:enrollment, url: enroll_path) do |f| %>
  <div class="actions">
    <%= f.hidden_field(:enrollment, :course_name => searchResult.name) %>
    <%= f.hidden_field(:enrollment, :user_id => current_user) %>
    <%= f.submit "Enroll"%>
  </div>
<% end %>

searchResult.name)%%>
当前用户)%>