【问题标题】:NoMethodError in Pins#show引脚中的 NoMethodError#show
【发布时间】:2016-01-05 11:54:15
【问题描述】:

我正在创建一个博客网站,但我正在努力添加评论部分。我安装了 commontator gem 并按照步骤操作。我的用户模型中有acts_as_commontatoracts_as_commontable 在我的别针模型中。 <%= commontator_thread(@commontable) %> 在我的别针展示中。

我收到 NoMethodError。我不明白为什么当我的模型中有方法时它不理解我的方法调用。

我的 Pin 图 show.html.erb

<div class="row">
  <div class="col-md-offset-2 col-md-8">
   <div class="panel panel-default">
    <div class="panel-heading center">
     <%= image_tag @pin.image.url(:medium) %>
    </div>
     <div class="panel-body">
      <p><%= @pin.description %></p>
      <p><strong><%= @pin.user.name if @pin.user %></strong></p>

      <% if @pin.user == current_user %>
      <%= link_to 'Edit', edit_pin_path(@pin) %>
      <% end %>
     </div>
    </div>
    <%= commontator_thread(@commontable) %>
  </div>
 </div>

</div>

我的模特 Pin.erb

class Pin < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>", :thumb =>          "100x100>" }
validates_attachment_content_type :image, :content_type => ["image/jpg",    "image/jpeg", "image/png", "image/gif"]
validates :image, presence: true
acts_as_commontable
end

我的模型用户.erb

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

 has_many :pins

 validates :name, presence: true
acts_as_commontator
end

【问题讨论】:

  • 包含堆栈跟踪的相关部分以及其中指示的区域周围的代码会很有帮助...
  • 您是否在控制器文件中添加了commontator_thread_show(commontable)
  • 不要张贴(链接到)代码图片。键入它们。不要偷懒。不要指望别人做你的事。
  • 我尝试将 commontator_thread_show(commontable) 添加到我的应用程序控制器或 Pins 控制器,但最终出现路由错误
  • 您可以尝试使用&lt;%= commontator_thread(@pin) %&gt; 代替commontator_thread_show(commontable) 吗?如果这不起作用,请尝试参考:stackoverflow.com/questions/22342512/…

标签: ruby-on-rails ruby


【解决方案1】:

最常见的问题是您的 @commontable 变量为 nil,然后您得到 NoMethodError ,它期望得到一个 :id。

检查@commontable 是否不为零也尝试用你的@pin 更改@commontable,因为他没有在编辑路径上抛出任何错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多