自从我买了一台新的基于 ARM 的 M1 MacBook Pro,我就一直遇到严重且一致的 PostgreSQL 问题 (psql 13.1)。无论我使用 Rails 服务器还是 Foreman,我都会在浏览器和终端中收到错误,例如PG::InternalError: ERROR: could not read block 15 in file "base/147456/148555": Bad addressorPG::Error (invalid encoding name: unicode)或Error during failsafe response: PG::UnableToSend: no connection to the server。奇怪的是,我经常可以反复刷新浏览器以使其正常工作(直到它们不可避免地再次出现)。
我知道与基于 ARM 的 M1 Mac 相关的所有配置挑战,这就是为什么我以多种方式多次卸载并重新安装从 Homebrew 到 Postgres 的所有内容(使用 Rosetta,不使用 Rosetta,使用arch -x86_64 brew命令,使用 Postgres 应用程序)而不是 Homebrew 安装)。我在随机留言板上遇到了其他几个人,他们遇到了同样的问题(也在新的 Mac 上)并且没有任何运气,这就是为什么我不愿意相信这是一个驱动器损坏问题。(我也多次运行磁盘工具急救检查;它说一切正常,但我不知道它有多可靠。)
我正在使用thoughtbot parity 将我的开发环境数据库与当前生产中的数据库同步。当我运行时development restore production,我在终端中得到数百行,看起来像下面的输出(这是在下载完成后立即但在继续创建默认值、处理数据、序列集等之前)。我相信这是问题的根源,但我不确定解决方案是什么:
pg_restore: dropping TABLE [table name1]
pg_restore: from TOC …Run Code Online (Sandbox Code Playgroud) pg-restore thoughtbot macos-big-sur postgresql-13 apple-silicon
我似乎无法找到有关如何修改管理gem的默认仪表板的任何文档,以便自定义索引和显示页面中显示的内容.这是我的具体目标:
Article belongs_to一个Author现在,相反,我得到了一个不那么有用的"作者#4"作为唱片公司.这是自动生成的仪表板:
class ArticleDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
author: Field::BelongsTo,
id: Field::Number,
title: Field::String,
content: Field::Text,
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
[snip]
end
Run Code Online (Sandbox Code Playgroud)
" 自定义仪表板 "文档页面显示:
每个Field类型都使用一组不同的选项,这些选项通过
.with_options类方法指定.
所以我想,在调用with_options上Field::BelongsTo可能是要走的路,但哪些选项可用于该字段(或任何其他为此事)?
使用 Thoughtbot 的 Administrate gem 编辑表单时,选择字段或 HasMany 关系的下拉选项始终显示给定模型/关联的所有可能记录。
但是,我只想显示与当前用户相关的记录,并且最好不要破坏管理控制器或视图。
使用“解决管理”的 Pundit 范围似乎只影响索引页,而不影响表单。
有没有人遇到过或优雅地解决了这个问题?
我正在尝试将Rails应用程序从使用Paperclip转换为ActiveStorage,并且遇到迁移指南中提供的ConvertToActiveStorage迁移脚本的问题。 https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md#copy-the-database-data-over
以下是我尝试运行Paperclip到ActiveStorage迁移时遇到的错误。我不确定是什么问题ActiveRecord::Base.connection.execute_prepared
Paperclip当前保存用户上载文件的路径是,迁移后/web/non-public/system/articles/documents/000/000/ActiveStorage应该将其保存到新位置/web/storage。
== 20190123165105 ConvertToActiveStorage: migrating ===========================
-- transaction()
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `execute_prepared' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x007fd7e9211128>
Did you mean? exec_delete
/web/db/migrate/20190123165105_convert_to_active_storage.rb:45:in `block (4 levels) in up'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:40:in `each'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:40:in `block (3 levels) in up'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:39:in `each'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:39:in `block (2 levels) in up'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:28:in `each'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:28:in `block in up'
/web/db/migrate/20190123165105_convert_to_active_storage.rb:27:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Caused by:
NoMethodError: undefined method `execute_prepared' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x007fd7e9211128> …Run Code Online (Sandbox Code Playgroud)