为什么帖子标题没有出现?

时间:2018-04-10 09:57:27

标签: ruby-on-rails ruby

所以这是:enter image description here 出于某种原因,这并没有显示我的帖子的标题。 但是,当我按下show选项并进入发布页面时,您可以看到详细信息。

  _form.html.erb
  <%= form_with(model: post, local: true) do |form| %>
  <% if post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% post.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= form.label :date %>
    <%= form.datetime_select :date, id: :post_date %>
  </div>

  <div class="field">
    <%= form.label :name %>
    <%= form.text_area :name, id: :post_name %>
  </div>

  <div class="field">
    <%= form.label :user_id %>
    <%= form.number_field :user_id, id: :post_user_id, value: current_user.id %>

  </div>

  <div class="field">
    <%= form.label :description %>
    <%= form.text_area :description, id: :post_description %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

#show.html.erb

<p id="notice"><%= notice %></p>

<p>
  <strong>Date:</strong>
  <%= @post.date %>
</p>

<p>
    <strong>Name:</strong>
    <%= @post.name %>
</p>

<p>
  <strong>User:</strong>
  <%= @post.user_id %>
</p>

<p>
  <strong>Description:</strong>
  <%= @post.description %>
</p>

<% if current_user == @post.user %>
 <%= link_to 'Edit', edit_post_path(@post) %> |
<%end%>
 <%= link_to 'Back', posts_path %>




<h1>Editing Post</h1>

<%= render 'form', post: @post %>

<%= link_to 'Show', @post %> |
<%= link_to 'Back', posts_path %>

edit.html.erb

<%= render 'form', post: @post %>

<%= link_to 'Show', @post %> |
<%= link_to 'Back', posts_path %>

我尝试过更改<%= form.text_area :name, id: :post_name %> to string_area:name和string_field但它们都没有工作。 事实上,当我将其更改为最后2时,如果我进入编辑页面,则会出现方法错误。我对rails和ruby还是比较新的,所以我非常感谢一些帮助。我确实尝试谷歌但是没有成功,我想我不知道该搜索什么,或者我说错了。

0 个答案:

没有答案