ruby-on-rails - 制作一个类方法来统计评论
问题描述
我正在学习 Ruby on Rails,我想创建一个类方法来计算文章评论。我正在创建这个类方法
class_methods do
def comment_count
end
end
这是我的模式
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "status", default: "public"
end
create_table "comments", force: :cascade do |t|
t.string "commenter"
t.text "body"
t.integer "article_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "status"
t.index ["article_id"], name: "index_comments_on_article_id"
end
add_foreign_key "comments", "articles"
解决方案
推荐阅读
- unity3d - 带有 Webgl 套接字异常错误的 Unity Mirror
- laravel - Windows 机器上 NGINX 中的 Laravel Route 无法正常工作
- javascript - 从 NodeJS+ExpressJS 的服务器内的目录中获取 JSON
- elasticsearch-curator - 是否可以在不丢失目标索引中的更新的情况下使用 elasticsearch-curator 拍摄快照和还原?
- android - 在 onActivityCreated 或 onViewCreated 中观察 LiveData 是否安全
- javascript - Tippy.js 自定义主题未应用
- sql - 在 Oracle SQL 中创建表时,如何创建包含特定值的列?
- docker - AppVeyor 上 Aspnet 图像的 OSversion 和其他属性不匹配
- java - 有没有办法在java中嵌入logstash
- php - 在 Windows 上的 Apache HTTPD 上记录 PHP 错误:此配置有什么问题,它没有记录错误?