在一对ovz-6服务器和同一个rubyonrails应用程序中,简单的selectpost注解(一对多关联)
<%= @post.comments.each do |c| %>
<%= c.body %>
<% end %>
正在显示现有的三条注解,但在结尾显示了一些完整的记录:
Great solution for a big and old problem.
This is a problem that I have started to web design years ago.
Thanks for facilitating this css files, this really help us!
[#<Comment id: 2, body: "Great solution for a big and old problem.",
post_id: 2, created_at: "2018-01-11 10:28:08", updated_at: "2018-01-11
10:28:08">, #<Comment id: 3, body: "This is a problem that I have
started to web desig...", post_id: 2, created_at: "2018-01-11
10:28:08", updated_at: "2018-01-11 10:28:08">, #<Comment id: 4, body:
"Thanks for facilitating this css files, this reall...", post_id: 2,
created_at: "2018-01-11 13:02:33", updated_at: "2018-01-11 13:02:33">]
如果没有注解,则显示:[]
debian-8的两个服务器(一个新服务器和另一个升级服务器)的配置如下:
debian gnu/linux 9(stretch)、linux 4.9.0-1-amd64、x86-64。apache 2.4.25(debian)。mysql 15.1发行版10.1.26-mariadb,debian linux gnu(x86_64),readline 5.2(状态如下)phusion乘客5.1.12。rvm 1.29.3。ruby 2.4.3p205(2017-12-14修订版61247)[x86\u 64-linux]。轨道5.1.4。mysql2(0.4.10)
bbdd状态为:
`$ sudo service mysql status`
mariadb.service - MariaDB 10.2.12 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; ven
Drop-In: /etc/systemd/system/mariadb.service.d
+-migrated-from-my.cnf-settings.conf
Active: active (running) since Wed 2018-01-10 11:58:23 UTC; 1 day
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 481 ExecStartPost=/bin/sh -c systemctl unset-environment
Process: 478 ExecStartPost=/etc/mysql/debian-start (code=exited, s
Process: 208 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recove
Process: 202 ExecStartPre=/bin/sh -c systemctl unset-environment _
Process: 190 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root
Main PID: 393 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
+-393 /usr/sbin/mysqld
sql文件是:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE ar_internal_metadata (
key varchar(255) COLLATE utf8_bin NOT NULL,
value varchar(255) COLLATE utf8_bin DEFAULT NULL,
created_at datetime NOT NULL,
updated_at datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
INSERT INTO ar_internal_metadata (key, value, created_at, updated_at) VALUES
('environment', 'development', '2018-01-10 16:44:47', '2018-01-10 16:44:47');
CREATE TABLE comments (
id bigint(20) NOT NULL,
body varchar(255) COLLATE utf8_bin DEFAULT NULL,
post_id bigint(20) DEFAULT NULL,
created_at datetime NOT NULL,
updated_at datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE posts (
id bigint(20) NOT NULL,
title varchar(255) COLLATE utf8_bin DEFAULT NULL,
body text COLLATE utf8_bin DEFAULT NULL,
created_at datetime NOT NULL,
updated_at datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE schema_migrations (
version varchar(255) COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ALTER TABLE comments
ADD CONSTRAINT fk_rails_2fd19c0db7 FOREIGN KEY (post_id) REFERENCES posts (id);
schema.rb文件是:
ActiveRecord::Schema.define(version: 20180111151927) do
create_table "posts", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin" do |t|
t.string "body"
t.bigint "post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_comments_on_post_id"
end
add_foreign_key "comments", "posts"
end
通过rails控制台,select post.last.comments可以很好地显示注解。
在其他同样使用支架构建的ror应用程序中,show注解会产生相同的错误:
Comments
congratulations!
[#<Comment id: 1, body: "congratulations!", post_id: 1, created_at:
"2018-01-11 17:13:26", updated_at: "2018-01-11 17:13:26">]
有什么问题吗?我们如何修正这个错误?你建议如何进行?提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!