首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Active Admin外键关系无方法错误

Active Admin外键关系无方法错误
EN

Stack Overflow用户
提问于 2021-05-06 16:59:39
回答 1查看 61关注 0票数 0

我第一次使用Active Admin制作了一个笔记应用程序,我遇到了一个让我困惑的错误,因为关系存在,我的迁移就像我在模式中看到的那样存在。我目前有两个型号的Note,即belongs_to ContentContent has_many :notes。我正在尝试自定义我的显示内容,以便它将显示不同,如下所示,但我一直得到一个无方法错误的notes此关系是存在的,应该工作,因为它是两个表之间的外键?

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Note < ApplicationRecord
  belongs_to :content
end
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Content < ApplicationRecord
    has_many :notes
end
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ActiveAdmin.register Content do
    permit_params :name, note_ids: []

show title: 'Test' do
    h3 'You have ' + pluralize(content.notes.count, 'note') + ' referencing ' + `#{content.name}`
end
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ActiveRecord::Schema.define(version: 2021_05_06_140826) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "active_admin_comments", force: :cascade do |t|
    t.string "namespace"
    t.text "body"
    t.string "resource_type"
    t.bigint "resource_id"
    t.string "author_type"
    t.bigint "author_id"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
    t.index ["namespace"], name: "index_active_admin_comments_on_namespace"
    t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
  end

  create_table "admin_users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["email"], name: "index_admin_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
  end

  create_table "contents", force: :cascade do |t|
    t.string "name"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  create_table "notes", force: :cascade do |t|
    t.string "title"
    t.text "body"
    t.bigint "content_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["content_id"], name: "index_notes_on_content_id"
  end

  add_foreign_key "notes", "contents"
end

EN

回答 1

Stack Overflow用户

发布于 2021-05-06 20:01:56

您确定内容是ActiveRecord对象吗?它看起来像是ActiveSupport SafeBuffer的实例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67422770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文