Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 不能';找不到与';id'=_Ruby On Rails_Comments - Fatal编程技术网

Ruby on rails 不能';找不到与';id'=

Ruby on rails 不能';找不到与';id'=,ruby-on-rails,comments,Ruby On Rails,Comments,我试图确保评论可以属于一篇文章,也可以拥有属于每个用户的ID。也就是说,我希望能够呈现评论,并让它说出是哪个用户发布了该评论。到目前为止,通过阅读其他人的问题,我仍然无法解决这个问题!我感谢所有的帮助和提前感谢!评论不会呈现在仪表板上 这是我的用户_controller.rb(仅限有用位) class UsersController 编辑:这里是my_comment.html.erb <%- @posts.each do |post| %> <div class="p

我试图确保评论可以属于一篇文章,也可以拥有属于每个用户的ID。也就是说,我希望能够呈现评论,并让它说出是哪个用户发布了该评论。到目前为止,通过阅读其他人的问题,我仍然无法解决这个问题!我感谢所有的帮助和提前感谢!评论不会呈现在仪表板上

这是我的用户_controller.rb(仅限有用位)

class UsersController
这是我的dashboard.html.erb

<%- @posts.each do |post| %>
    <div class="panel panel-default">
        <div class="panel-heading-gray"> <%= image_tag @user.profile_picture.url(:thumb) %> <h5 class="user-name"><%= @user.name %></h5> <h6 class="time-posted"><%= post.created_at.strftime("%B, %d, %Y") %></h6></div>
        <div class="panel-body"><%= link_to post.body, post %></div>
        <div class="panel-footer"> 
            <h2>Add a comment:</h2>
            <%= render post.comments %>
            <p class="Like-option">Like ·</p>
            <p class="comment-form">Comment - <%= @post.comments.count %></p>  
            <p class="view-option">· View</p>
            <p class="comment-profile-picture">
            <%= image_tag @user.profile_picture.url(:thumb) %></p>
            <div class="comments-stream">
            <%= render @post.comments %>
        </div>
        <div id="comments-form">
            <%=  render "comments/form", :post => post %>
        </div>  
    </div> 
<!-- Other non-comments related code here -->
<% end %>
<div class="comment clearfix">
    <div class="comment_content">
        <p class="comment_body"><%= comment.body %></p>

        <% if @user_signed_in %>
            <p><%= link_to "Delete", [comment.post, comment],
                        method: :delete, 
                        class: "button",
                        data: { confirm: "Are you sure?" } %>
            </p>
        <% end %>
    </div>
</div>
<%= form_for([@post, @post.comments.build]) do |f| %>
    <p>
        <%= f.text_area :body, placeholder: "Write a comment!" %>
    </p>
    <br>
    <p> <%= f.submit %> </p>

<% end %>

添加评论:

Like·

评论-

·查看

post%>
编辑:这里是my_comment.html.erb

<%- @posts.each do |post| %>
    <div class="panel panel-default">
        <div class="panel-heading-gray"> <%= image_tag @user.profile_picture.url(:thumb) %> <h5 class="user-name"><%= @user.name %></h5> <h6 class="time-posted"><%= post.created_at.strftime("%B, %d, %Y") %></h6></div>
        <div class="panel-body"><%= link_to post.body, post %></div>
        <div class="panel-footer"> 
            <h2>Add a comment:</h2>
            <%= render post.comments %>
            <p class="Like-option">Like ·</p>
            <p class="comment-form">Comment - <%= @post.comments.count %></p>  
            <p class="view-option">· View</p>
            <p class="comment-profile-picture">
            <%= image_tag @user.profile_picture.url(:thumb) %></p>
            <div class="comments-stream">
            <%= render @post.comments %>
        </div>
        <div id="comments-form">
            <%=  render "comments/form", :post => post %>
        </div>  
    </div> 
<!-- Other non-comments related code here -->
<% end %>
<div class="comment clearfix">
    <div class="comment_content">
        <p class="comment_body"><%= comment.body %></p>

        <% if @user_signed_in %>
            <p><%= link_to "Delete", [comment.post, comment],
                        method: :delete, 
                        class: "button",
                        data: { confirm: "Are you sure?" } %>
            </p>
        <% end %>
    </div>
</div>
<%= form_for([@post, @post.comments.build]) do |f| %>
    <p>
        <%= f.text_area :body, placeholder: "Write a comment!" %>
    </p>
    <br>
    <p> <%= f.submit %> </p>

<% end %>

为了以防万一,这里是我的评论表单_form.html.erb

<%- @posts.each do |post| %>
    <div class="panel panel-default">
        <div class="panel-heading-gray"> <%= image_tag @user.profile_picture.url(:thumb) %> <h5 class="user-name"><%= @user.name %></h5> <h6 class="time-posted"><%= post.created_at.strftime("%B, %d, %Y") %></h6></div>
        <div class="panel-body"><%= link_to post.body, post %></div>
        <div class="panel-footer"> 
            <h2>Add a comment:</h2>
            <%= render post.comments %>
            <p class="Like-option">Like ·</p>
            <p class="comment-form">Comment - <%= @post.comments.count %></p>  
            <p class="view-option">· View</p>
            <p class="comment-profile-picture">
            <%= image_tag @user.profile_picture.url(:thumb) %></p>
            <div class="comments-stream">
            <%= render @post.comments %>
        </div>
        <div id="comments-form">
            <%=  render "comments/form", :post => post %>
        </div>  
    </div> 
<!-- Other non-comments related code here -->
<% end %>
<div class="comment clearfix">
    <div class="comment_content">
        <p class="comment_body"><%= comment.body %></p>

        <% if @user_signed_in %>
            <p><%= link_to "Delete", [comment.post, comment],
                        method: :delete, 
                        class: "button",
                        data: { confirm: "Are you sure?" } %>
            </p>
        <% end %>
    </div>
</div>
<%= form_for([@post, @post.comments.build]) do |f| %>
    <p>
        <%= f.text_area :body, placeholder: "Write a comment!" %>
    </p>
    <br>
    <p> <%= f.submit %> </p>

<% end %>




如果您需要查看更多的代码或任何东西,请发表评论并让我知道,谢谢大家

如果在仪表板操作中调用
raise params.inspect
,您将看到没有此类属性comment\u id。但是,您的
@comment
定义正在尝试调用一个属性comment\u id。你根本不需要这个

在您的视图中,您甚至都没有引用
@comment
。至于添加发表评论的用户的用户名或图片,您必须将其放在您的评论部分
视图/comments/_comment.html.erb
——因为这就是所呈现的内容,每个评论一次

比如:

<div class="comment clearfix">
  <div class="comment_content">
    <p class="comment_body">
      <span class="commentor"><%= comment.user.name %></span>
      <span class="body"><%= comment.body %></span>
    </p>
    <% if @user_signed_in %>          
      <p><%= link_to "Delete", [comment.post, comment],
                    method: :delete, 
                    class: "button",
                    data: { confirm: "Are you sure?" } %>
      </p>
    <% end %>
  </div>
</div>


我在评论中明确表示,不会在仪表板上显示。这意味着这里显示的代码中只有一部分存在问题,所以是的,我已经尝试隔离。发布这个问题是希望得到答案,而不是想耍聪明的人。所以,谢谢你,祝你有一个好的。你发布的UsersController中的“唯一一点代码”也是这样吗?还是你的评论控制者?还是风景?还是你的路线不好?你张贴了所有这些,显然是希望人们能涉水而过,即使你已经“试图孤立”。现在你想得到一个关于它的态度?我不认为问题出在你的代码上。我很确定我在寻求帮助,有一个好的帮助。正如@MarsAtomic所说,你已经发布了很多代码要筛选-而不仅仅是必要的部分文件-但我没有看到以下内容:你的代码在show中的编写方式是
视图/注释/_comment.html.haml
,这就是结果。此外,您在仪表板上没有“单个”注释,因此不要尝试搜索。如果我没有在仪表板中查找,则会出现此错误。nil的未定义方法“comments”:nilclass我知道你在说什么,但是在做了这些更改之后,我仍然在仪表板上看到这个错误。显示C:/row/website/app/views/comments/_comment.html.erb,其中第4行出现:未定义的#So yes的“user”方法。。。你怎么认为?