RoR 4 - 搜索表单未显示

时间:2013-07-11 14:59:37

标签: ruby-on-rails layout search-form

我正在构建一个RoR搜索表单。 (代码提取看起来很长但非常简单。)

这是内容 app / views / layouts / application.html.erb 文件

<!DOCTYPE html>
<html>
<head>
  <title><%= controller.action_name %></title>
  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
</head>
<body>
        <span style="text-align: right">
                <% form_tag "/client_workouts/find" do %>
                        <%= text_field_tag :search_string %>
                        <%= submit_tag "Search" %>
                <% end %>
        </span>

        <p style="color: green"><%= flash[:notice] %></p>

        <%= yield %>

</body>
</html>

这是 app / views / client_workouts / index.html.erb 文件的内容

<h1>Listing client_workouts</h1>

<table>
  <thead>
    <tr>
      <th>Client name</th>
      <th>Trainer</th>
      <th>Duration mins</th>
      <th>Date of workout</th>
      <th>Paid amount</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @client_workouts.each do |client_workout| %>
      <tr>
        <td><%= client_workout.client_name %></td>
        <td><%= client_workout.trainer %></td>
        <td><%= client_workout.duration_mins %></td>
        <td><%= client_workout.date_of_workout %></td>
        <td><%= client_workout.paid_amount %></td>
        <td><%= link_to 'Show', client_workout %></td>
        <td><%= link_to 'Edit', edit_client_workout_path(client_workout) %></td>
        <td><%= link_to 'Destroy', client_workout, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Client workout', new_client_workout_path %>

这是浏览器页面的输出http://rubyonrails/client_workouts

<html><head>
  <title>index</title>
  <link rel="stylesheet" media="all" href="/assets/application.css?body=1" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/stylesheets/ads.css.bak.css" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/assets/client_workouts.css?body=1" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/assets/events.css?body=1" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/assets/scaffolds.css?body=1" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/assets/tickets.css?body=1" data-turbolinks-track="true">
<link rel="stylesheet" media="all" href="/assets/welcome.css?body=1" data-turbolinks-track="true">
  <script src="/assets/jquery.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/jquery_ujs.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/turbolinks.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/ads.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/client_workouts.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/events.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/tickets.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/welcome.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/application.js?body=1" data-turbolinks-track="true"></script>
  <meta name="csrf-param" content="authenticity_token">
<meta name="csrf-token" content="i4JT3M6zVgdVPXQoW2hNcD+MlA7TpGsiNkBxAD3LuAg=">
</head>
<body>
    <span style="text-align: right">
    </span>

    <p style="color: green"></p>

    <h1>Listing client_workouts</h1>

<table>
  <thead>
    <tr>
      <th>Client name</th>
      <th>Trainer</th>
      <th>Duration mins</th>
      <th>Date of workout</th>
      <th>Paid amount</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>
      <tr>
        <td>Tuyen</td>
        <td>Julie</td>
        <td>20</td>
        <td>2013-07-11</td>
        <td>20</td>
        <td><a href="/client_workouts/1">Show</a></td>
        <td><a href="/client_workouts/1/edit">Edit</a></td>
        <td><a rel="nofollow" href="/client_workouts/1" data-method="delete" data-confirm="Are you sure?">Destroy</a></td>
      </tr>
      <tr>
        <td>Thuy</td>
        <td>Julie</td>
        <td>30</td>
        <td>2013-07-11</td>
        <td>30</td>
        <td><a href="/client_workouts/2">Show</a></td>
        <td><a href="/client_workouts/2/edit">Edit</a></td>
        <td><a rel="nofollow" href="/client_workouts/2" data-method="delete" data-confirm="Are you sure?">Destroy</a></td>
      </tr>
  </tbody>
</table>

<br>

<a href="/client_workouts/new">New Client workout</a>

</body></html>

查看正文标记下方的范围标记,没有搜索表单。

你知道我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:2)

您需要<%= form_tag ... %>而不是<% form_tag %>。 =是告诉rails输出表单的内容。