0

我正在构建一个 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>

查看body标签正下方的span标签,没有搜索表单。

你知道我在这里想念什么吗?

4

1 回答 1

2

<%= form_tag ... %>不需要<% form_tag %>。= 告诉 rails 输出表单。

于 2013-07-11T15:03:03.153 回答