rails 4 deep_clone development/staging 和生产不同
rails 4 deep_clone different in development/staging and production
我是 运行 一个 rails 4 应用程序。到目前为止一切正常,但现在 gem deep_clonable 中的 deep_clone 发生了一个奇怪的错误。我制作了一个控制器方法来复制一个条目(交互 model/controller)。
interactions_controller.rb:
def duplicate
@interaction = Interaction.find(params[:id]).deep_clone include: [ :interaction_solvents, :interaction_additives], skip_missing_associations: true
@interaction.user = current_user
respond_to do |format|
if @interaction.save
format.html { redirect_to @interaction, notice: 'Item was successfully cloned.' }
else
format.html { redirect_to Interaction.find(params[:id]), notice: 'ERROR: Item can\'t be cloned.'}
end
end
end
我使用 docker 开发并使用 capistrano 将代码部署到暂存和生产服务器。暂存服务器和生产服务器是相同的,我在 ENV=production 中部署。对于部署,我使用两个文件,它们仅在 IP 上有所不同,并且缺少用于暂存的部署备份。
config/deploy/production.rb:
user = 'prod'
before 'deploy:migrate', 'deploy:backup'
server 'XXX.XX.146.242', user: user, roles: %w{app web db}
puts %w(publickey)
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey)
}
#set :pty, false
set :linked_files, fetch(:linked_files, []).push(
'.ruby-version',
'.ruby-gemset'
)...
config/deploy/staging.rb:
user = 'prod'
#before 'deploy:migrate', 'deploy:backup'
server 'XXX.XX.146.243', user: user, roles: %w{app web db}
puts %w(publickey)
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey)
}
#set :pty, false
set :linked_files, fetch(:linked_files, []).push(
'.ruby-version',
'.ruby-gemset'
)
#set :tmp_dir, "/home/#{user}/tmp"
set :user, user
现在来了。调用重复项的所有内容在开发和暂存中都绝对可以正常工作。在生产中,复制加倍并生成 2 个新副本。我更新了两台服务器并检查了版本。以下是一些规格:
- Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-36-通用 x86_64)
- nginx 版本:nginx/1.14.0 (Ubuntu)
- Rails 4.2.10
- postgres (PostgreSQL) 10.12 (Ubuntu 10.12-0ubuntu0.18.04.1)
部分生产日志:
I, [2020-06-25T15:02:10.184115 #32495] INFO -- : Started GET "/interactions/7336/duplicate" for 127.0.0.1 at 2020-06-25 15:02:10 +0200
I, [2020-06-25T15:02:10.186316 #32495] INFO -- : Processing by InteractionsController#duplicate as HTML
I, [2020-06-25T15:02:10.186455 #32495] INFO -- : Parameters: {"id"=>"7336"}
...
I, [2020-06-25T15:02:11.514185 #32495] INFO -- : Redirected to http://suprabank.org/interactions/7338
I, [2020-06-25T15:02:11.514595 #32495] INFO -- : Completed 302 Found in 1328ms (ActiveRecord: 32.0ms)
I, [2020-06-25T15:02:11.590073 #32495] INFO -- : Started GET "/interactions/7336/duplicate" for 127.0.0.1 at 2020-06-25 15:02:11 +0200
I, [2020-06-25T15:02:11.592145 #32495] INFO -- : Processing by InteractionsController#duplicate as HTML
I, [2020-06-25T15:02:11.592555 #32495] INFO -- : Parameters: {"id"=>"7336"}
...
I, [2020-06-25T15:02:12.705493 #32495] INFO -- : Redirected to http://suprabank.org/interactions/7339
I, [2020-06-25T15:02:12.705750 #32495] INFO -- : Completed 302 Found in 1113ms (ActiveRecord: 23.1ms)
I, [2020-06-25T15:02:12.789812 #32495] INFO -- : Started GET "/interactions/7339" for 127.0.0.1 at 2020-06-25 15:02:12 +0200
I, [2020-06-25T15:02:12.791400 #32495] INFO -- : Processing by InteractionsController#show as HTML
I, [2020-06-25T15:02:12.791546 #32495] INFO -- : Parameters: {"id"=>"7339"}
从日志看来,条目 7336 的第一次重复似乎工作正常,但随后路由走错了方向,调用了 7336/duplicate 上的另一个 GET 请求。这不应该发生,也不会在分期中发生。在那个小绕道服务器正确加载(第二个)重复条目 7339 的显示操作之后。
我更新了两个服务器并重新启动了 nginx,但是相同的暂存服务器和生产服务器之间的操作始终不匹配?
知道错误是什么吗?
提前致谢,
斯蒂芬
感谢创造gemdeep_clonable的moiristo!他用他的经验帮助了我(我在 GitHub 回购上创建了一个问题来联系他),gem 没有任何错误!
我将操作重新路由为 POST 方法而不是 GET。
routes.rb:
post 'interactions/:id/duplicate', to: 'interactions#duplicate'
index.html.rb:
<%= link_to "", {controller: "interactions", action: 'duplicate', id: interaction.id}, class:'fa fa-clone', :method=>:post%>
在生产服务器上成功了。
感谢您的帮助,尤其是 moiristo。
问候,
斯蒂芬
我是 运行 一个 rails 4 应用程序。到目前为止一切正常,但现在 gem deep_clonable 中的 deep_clone 发生了一个奇怪的错误。我制作了一个控制器方法来复制一个条目(交互 model/controller)。
interactions_controller.rb:
def duplicate
@interaction = Interaction.find(params[:id]).deep_clone include: [ :interaction_solvents, :interaction_additives], skip_missing_associations: true
@interaction.user = current_user
respond_to do |format|
if @interaction.save
format.html { redirect_to @interaction, notice: 'Item was successfully cloned.' }
else
format.html { redirect_to Interaction.find(params[:id]), notice: 'ERROR: Item can\'t be cloned.'}
end
end
end
我使用 docker 开发并使用 capistrano 将代码部署到暂存和生产服务器。暂存服务器和生产服务器是相同的,我在 ENV=production 中部署。对于部署,我使用两个文件,它们仅在 IP 上有所不同,并且缺少用于暂存的部署备份。
config/deploy/production.rb:
user = 'prod'
before 'deploy:migrate', 'deploy:backup'
server 'XXX.XX.146.242', user: user, roles: %w{app web db}
puts %w(publickey)
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey)
}
#set :pty, false
set :linked_files, fetch(:linked_files, []).push(
'.ruby-version',
'.ruby-gemset'
)...
config/deploy/staging.rb:
user = 'prod'
#before 'deploy:migrate', 'deploy:backup'
server 'XXX.XX.146.243', user: user, roles: %w{app web db}
puts %w(publickey)
set :ssh_options, {
forward_agent: true,
auth_methods: %w(publickey)
}
#set :pty, false
set :linked_files, fetch(:linked_files, []).push(
'.ruby-version',
'.ruby-gemset'
)
#set :tmp_dir, "/home/#{user}/tmp"
set :user, user
现在来了。调用重复项的所有内容在开发和暂存中都绝对可以正常工作。在生产中,复制加倍并生成 2 个新副本。我更新了两台服务器并检查了版本。以下是一些规格:
- Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-36-通用 x86_64)
- nginx 版本:nginx/1.14.0 (Ubuntu)
- Rails 4.2.10
- postgres (PostgreSQL) 10.12 (Ubuntu 10.12-0ubuntu0.18.04.1)
部分生产日志:
I, [2020-06-25T15:02:10.184115 #32495] INFO -- : Started GET "/interactions/7336/duplicate" for 127.0.0.1 at 2020-06-25 15:02:10 +0200
I, [2020-06-25T15:02:10.186316 #32495] INFO -- : Processing by InteractionsController#duplicate as HTML
I, [2020-06-25T15:02:10.186455 #32495] INFO -- : Parameters: {"id"=>"7336"}
...
I, [2020-06-25T15:02:11.514185 #32495] INFO -- : Redirected to http://suprabank.org/interactions/7338
I, [2020-06-25T15:02:11.514595 #32495] INFO -- : Completed 302 Found in 1328ms (ActiveRecord: 32.0ms)
I, [2020-06-25T15:02:11.590073 #32495] INFO -- : Started GET "/interactions/7336/duplicate" for 127.0.0.1 at 2020-06-25 15:02:11 +0200
I, [2020-06-25T15:02:11.592145 #32495] INFO -- : Processing by InteractionsController#duplicate as HTML
I, [2020-06-25T15:02:11.592555 #32495] INFO -- : Parameters: {"id"=>"7336"}
...
I, [2020-06-25T15:02:12.705493 #32495] INFO -- : Redirected to http://suprabank.org/interactions/7339
I, [2020-06-25T15:02:12.705750 #32495] INFO -- : Completed 302 Found in 1113ms (ActiveRecord: 23.1ms)
I, [2020-06-25T15:02:12.789812 #32495] INFO -- : Started GET "/interactions/7339" for 127.0.0.1 at 2020-06-25 15:02:12 +0200
I, [2020-06-25T15:02:12.791400 #32495] INFO -- : Processing by InteractionsController#show as HTML
I, [2020-06-25T15:02:12.791546 #32495] INFO -- : Parameters: {"id"=>"7339"}
从日志看来,条目 7336 的第一次重复似乎工作正常,但随后路由走错了方向,调用了 7336/duplicate 上的另一个 GET 请求。这不应该发生,也不会在分期中发生。在那个小绕道服务器正确加载(第二个)重复条目 7339 的显示操作之后。
我更新了两个服务器并重新启动了 nginx,但是相同的暂存服务器和生产服务器之间的操作始终不匹配?
知道错误是什么吗?
提前致谢, 斯蒂芬
感谢创造gemdeep_clonable的moiristo!他用他的经验帮助了我(我在 GitHub 回购上创建了一个问题来联系他),gem 没有任何错误!
我将操作重新路由为 POST 方法而不是 GET。
routes.rb:
post 'interactions/:id/duplicate', to: 'interactions#duplicate'
index.html.rb:
<%= link_to "", {controller: "interactions", action: 'duplicate', id: interaction.id}, class:'fa fa-clone', :method=>:post%>
在生产服务器上成功了。
感谢您的帮助,尤其是 moiristo。 问候, 斯蒂芬