【问题标题】:wrong number of arguments in product comments in railsRails 中产品评论中的参数数量错误
【发布时间】:2017-04-16 16:11:39
【问题描述】:

我正在尝试将 cmets 添加到我的产品中,当我提交评论时出现此错误

“产品中的参数错误#show

显示 C:/Sites/project/app/views/cmets/_comment.html.erb 其中第 3 行提出:

参数数量错误(给定 0,预期为 1..2)"

我的产品/SHOW.HTML.ERB

<body style="background-image:url('/images/Linux Wallpaper.jpg');">

<div class="panel panel-default panel-list" style="width:70%;margin:20px auto;background-color: rgba(255,255,255,0.1);">
    <div class="panel-heading" style="background-color:rgba(126, 232, 173, 0.78);">
        <h3 class="panel-title" style="font-family:lucida;display:bold;">
        <% if @product.user == current_user %>
          <p style="float: right;"><%= link_to 'Edit', edit_product_path(@product), :style=>"background-color:rgb(10, 245, 61);padding: 10px 10px 10px 10px;border-radius: 6px; border:1px solid rgba(255,255,255,0.9);"  %> </p>
<%end%>
          <p style="float: left;"><%= link_to 'Back', products_path, :style=>"background-color:rgb(10, 245, 61);padding: 10px 10px 10px 10px;border-radius: 6px; border:1px solid rgba(255,255,255,0.9);" %><p>
           <center>YOUR PRODUCT : <%=@product.title%></center> 
        </h3>
    </div>
    <div class="panel-body" style="background-color:rgba(255,255,255,0.1);">

    <div class="row">
        <div class="col-lg-9 col-md-4" style="padding-left:30px;">
            <%= image_tag(@product.img_url.url(:large),:style => "height:400px;width:800px;border-radius: 4px; border:1px solid rgba(255,255,255,0.9);") %>
        </div>
        <div class="col-lg-2 col-md-2">
              <strong style="color:yellow;font-size:2em;font-weight:bolder;">Name:</strong><br>
            <div style="color:lightgreen;font-size:2em;">
            <%= @product.title%>
                </div>
        </div>
             <div class="col-lg-3 col-md-3">
              <strong style="color:yellow;font-size:2em;font-weight:bolder;">File Type:</strong><br>
            <div style="color:lightgreen;font-size:2em;">
            <%= @product.filetype%>
                </div>
        </div>
<div style="float:right;padding-right:10%;">
<div class="col-lg-2 col-md-2">
  <strong style="color:yellow;font-size:2em;font-weight:bolder;">Price:</strong><br>
        <div style="color:lightgreen;font-size:2em;">
  $<%= @product.price %>
        </div>
        </div>
    </div>
    <div style="float:right;padding-right:10%;">
<div>
  <strong style="color:yellow;font-size:2em;font-weight:bolder;">Tags:</strong><br>
        <div style="color:lightgreen;font-size:2em;">
  $<%= @product.all_tags %>
        </div>
        </div>
<div>
<h2><%= @product.comments.count %> COMMENTS</h2>
<p><%= render @product.comments %></p>
<h3> ADD A COMMENT </h3>
<p><%= render 'comments/form' %></p>
</div>
    </div>
    </div>
</div>
</div>

我的 COMMENTS_CONTROLLER

class CommentsController < ApplicationController
    def create
        @product=Product.find(params[:product_id])
        @comment=@product.comments.create(params[:comment].permit(:body))
        redirect_to product_path(@product)
    end
end

_COMMENT.HTML.ERB

<p><%= current_user.name %></p>
<p><%= comment.body %></p>
<p><%= time_ago_in_words.(comment.created_at)%></p>

<p><%= link_to 'Delete',[comment.product,coment], method: :delete, data: { confirm: 'Are you sure?' } %>
</p>

【问题讨论】:

  • 错误提示ArgumentError in Products#showshow 操作吗?可以发一下吗?
  • 不是views,动作code
  • 显然在Products 控制器中。
  • 错误似乎在_comment 部分,你能证明一下吗?
  • 对不起,我以为我做到了,我的错

标签: ruby-on-rails


【解决方案1】:

从这行删除time_ago_in_words之后的多余点

= time_ago_in_words(comment.created_at)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2012-09-28
    • 2019-07-23
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多