1

我有一个用于创建和编辑新酒店的标准 rails form_for 标签。当通过 edit_hotels_path 访问时,这呈现得很好,但是当访问 new_hotels_path 时,html 表单标签被设置为display: none;导致表单仅在“新”视图中不显示。

我已经重新启动服务器,清空缓存,确保它们使用相同的 CSS,但它仍然呈现显示设置为无。以下是使用开发人员工具看到的样式

<form accept-charset="UTF-8" action="/hotels" class="new_hotel" id="new_hotel" method="post" style="display: none; "><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="pDlR3gV2tm+Z7xRFdC0uclNY13FlzxUSOjOrHs2ttO0="></div>

element.style {
display: none;
}

下面是正在呈现的 html 源代码,其中不包括 display: none;

    <form accept-charset="UTF-8" action="/hotels" class="new_hotel" id="new_hotel" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="pDlR3gV2tm+Z7xRFdC0uclNY13FlzxUSOjOrHs2ttO0=" /></div>

  <div class="control-group">
    <div class="controls">
    <input id="hotel_name" name="hotel[name]" placeholder="Name..." size="30" type="text" /><br>
        <select id="hotel_year" name="hotel[year]"><option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option></select><br>
        <select id="hotel_month" name="hotel[month]"><option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option></select><br>

    <textarea cols="40" id="hotel_body" name="hotel[body]" placeholder="Hotel info up to 1000 words..." rows="20">
</textarea><br>
    <input id="hotel_meta_tags" name="hotel[meta_tags]" placeholder="Enter meta tags for image, as a comma separated list..." size="30" type="text" /><br>
<legend>Winner</legend>
        <input name="hotel[winner]" type="hidden" value="0" /><input id="hotel_winner" name="hotel[winner]" type="checkbox" value="1" />
        <br/>

    </div>
<div class="form-actions">
    <input class="btn-large btn-success" name="commit" type="submit" value="create" />
  </div>
</div>
</form>

以下是代码,不胜感激。

_form.html.erb

<%= form_for @hotel do |f| %>
<% if @hotel.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(@hotel.errors.count, "error") %> prohibited this article from being saved:</h2>

    <ul>
    <% @hotel.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>


    <%= render partial: "shared/code_sheet" %>
  <div class="control-group">
    <div class="controls">
    <%= f.text_field :name, placeholder: "Name..." %><br>
        <%= f.select :year, [2012, 2013, 2014, 2015] %><br>
        <%= f.select :month, ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] %><br>

    <%= f.text_area :body, placeholder: "Hotel info up to 1000 words..." %><br>
    <%= f.text_field :meta_tags, placeholder: "Enter meta tags for image, as a comma separated list..." %><br>
<legend>Winner</legend>
        <%= f.check_box :winner %>
        <br/>

    </div>
<div class="form-actions">
    <%= f.submit "create", class: "btn-large btn-success" %>
  </div>
</div>
<% end %>

编辑.html.erb

<div class="container">
<h1>Editing hotel</h1>

<%= render "form" %>
<%= link_to 'hotels index', hotels_path %>
</div>

新的.html.erb

<div class="container">
<h1>New hotel</h1>

<%= render "form" %>
<%= link_to 'hotels index', hotels_path %>
</div>
4

1 回答 1

2

它可以是任何东西。你必须知道你的 CSS 中有什么。您是否搜索过“显示:无;” 在您的 CSS 文件中并检查匹配项?element.style 通常直接设置在 HTML 标签上。搜索视图并放置调试字符串以确保它正在拉取适当的 .html。

于 2012-09-27T16:28:51.717 回答