Gem 关于 cells 的一个错误

stephen · December 29, 2011 · Last by g_tree replied at September 18, 2012 · 3550 hits

按照 ruby-china 的 commetscell 写,但是运行时出现了这个错误 uninitialized constant CommentsCell::Comment,rails 3.1 and cells 3.8

class CommentsCell < Cell::Rails

  def show(opts)
    @commentable = opts[:commentable]
    @current_user = opts[:current_user]
    @comments = Comment.where(:commentable_type => @commentable.class.name, :commentable_id => @commentable.id)
    @comment = Comment.new(:commentable_type => @commentable.class.name, :commentable_id => @commentable.id)

    render
  end

end

目录结构 app/cells/comment_cell.rb app/cells/comments/ app/cells/comments/_comment.html.erb app/cells/comments/show.html.erb

ActionView::Template::Error (uninitialized constant CommentsCell::Comment):
    15:             </span>
    16:         </div>
    17:         <div class="comments_show">
    18:             <%= render_cell :comments, :show, :commentable => @micropost, :current_user => current_user %>
    19:         </div>
    20:     </td>
    21: </tr>
  app/cells/comments_cell.rb:6:in `show'

Comment Model 有吗?

@huacnlee 这里

class Comments < ActiveRecord::Base
  attr_accessible :comment

  belongs_to :user
  belongs_to :comentable, :polymorphic => true

  index :user_id
  index :commentable_type
  index :commentable_id

  validates_presence_of :comment
end

@huacnlee 原来是我的 model 问题,应该是 comment,而不是 comments

@huacnlee 又有这个错误了 model 我已经去到个 s····

ActionView::Template::Error (undefined method `index' for #<Class:0x007f980d7d53c8>):
    15:             </span>
    16:         </div>
    17:         <div class="comments_show">
    18:             <%= render_cell :comments, :show, :commentable => @micropost, :current_user => current_user %>
    19:         </div>
    20:     </td>
    21: </tr>
app/models/comment.rb:7:in `<class:Comment>'
  app/models/comment.rb:1:in `<top (required)>'
  app/cells/comments_cell.rb:6:in `show'

问题解决了么?

huacnlee in 提问要有方法 mention this topic. 03 Apr 10:56
You need to Sign in before reply, if you don't have an account, please Sign up first.