【问题标题】:keep content of my comment when i want edit him当我想编辑他时保留我的评论内容
【发布时间】:2021-06-05 18:10:42
【问题描述】:

我有用于我的八卦的 cmets,并在我的八卦节目中展示它们。

当我点击编辑我的八卦时,它会打开新窗口并显示实际的标题和内容。

但是当我点击编辑我的评论打开视图进行编辑时,内容是空白的。当我想编辑他时如何显示实际内容。

查看 - 编辑评论:

<%= form_for edit_gossip_comment_path do |f| %>
  <div class="form-group new-gossip-field">
    <%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
  </div>
  <div class="form-group margin-left-50">
    <button class="btn btn-primary" type="submit">Edit Comment</button>
  </div>
<% end %>

查看 - 编辑八卦:

<%= form_for @gossip do |f| %>
  <div class="form-group new-gossip-field">
    <%= f.text_field :title, placeholder: "Title", class: 'form-control' %>
  </div>
  <div class="form-group new-gossip-field">
    <%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
  </div>
  <div class="form-group margin-left-50">
    <button class="btn btn-primary" type="submit">Edit Gossip</button>
  </div>
<% end %>

如果我尝试让@comment 代替 edit_gossip_comment_path 不起作用,我真的不明白为什么。

如果您需要查看更多代码,请告诉我。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5 ruby-on-rails-6


    【解决方案1】:

    我认为问题出在你的编辑评论表单上,你没有传递评论,所以你应该传递表单的工作对象,比如:

    查看 - 编辑评论:

     <%= form_for @comment, url: edit_gossip_comment_path(@comment) do |f| %>
      <div class="form-group new-gossip-field">
        <%= f.text_area :content, placeholder: "Content", class: 'form-control' %>
      </div>
      <div class="form-group margin-left-50">
        <button class="btn btn-primary" type="submit">Edit Comment</button>
      </div>
    <% end %>
    

    这样,我相信您的评论内容会在表格中显示出来。

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 1970-01-01
      • 2014-03-29
      • 2021-09-29
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      相关资源
      最近更新 更多