- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个产品页面,当您购买产品时,它会重定向到购买页面(收据和下载页面)。
在我的本地计算机上开发时一切正常,但是当购买在远程服务器上进行生产时,它会向客户收费(使用 Stripe)但不会在 purchase
中创建一个条目表 - 不允许客户下载他们的产品。我检查了 psql
中的“购买”表在远程服务器上,它没有任何行/条目。
它应该也发送一封电子邮件 - 链接到购买页面,这也只在开发中有效。
我在本地计算机和远程服务器上都使用 PostgreSQL。
收费 Controller :
class ChargesController < ApplicationController
def new
set_meta_tags noindex: true
end
def create
pack = Pack.find(params[:product_id])
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken],
)
# Amount in cents
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => pack.price_in_cents,
:description => 'Product Purchase',
:currency => 'usd',
)
purchase = Purchase.create(
email: params[:stripeEmail],
card: params[:stripeToken],
amount: pack.price_in_cents,
description: charge.description,
currency: charge.currency,
customer_id: customer.id,
product_id: pack.id,
uuid: SecureRandom.uuid,
)
redirect_to purchase
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
purchases_controller:
class PurchasesController < ApplicationController
def show
@title = 'Purchase Receipt';
@purchase = Purchase.find_by_uuid(params[:id])
@pack = Pack.find(@purchase.product_id)
set_meta_tags noindex: true
end
end
购买模式:
class Purchase < ApplicationRecord
attr_accessor :download_token
after_create :email_purchaser
def to_param
uuid
end
def email_purchaser
PurchaseMailer.purchase_receipt(self).deliver
end
def Purchase.new_token
SecureRandom.urlsafe_base64
end
def create_download
self.download_token = Purchase.email.new_token
update_attribute(:download, Purchase.email(download_token))
update_attribute(:download_sent_at, Time.zone.now)
end
end
purchase_mailer:
class PurchaseMailer < ActionMailer::Base
layout 'purchase_mailer'
default from: "First Last <myemail@gmail.com>"
def purchase_receipt purchase
@purchase = purchase
mail to: purchase.email, subject: "Thank you for your purchase. Here's your download link, enjoy!"
end
end
购买链接。在发送的电子邮件中显示 View :
<%= link_to "DOWNLOAD", purchase_url(@purchase), target: "_blank" %>
这是服务器日志:
I, [2019-01-11T22:04:21.404919 #17222] INFO -- : [14c2eed0-3aae-4ab6-8142-9aa9744819af] Started HEAD "/https://mywebsite.com/" for XX.XXX.XXX.XXX at 2019-01-11 22:04:21 +0000
F, [2019-01-11T22:04:21.405538 #17222] FATAL -- : [14c2eed0-3aae-4ab6-8142-9aa9744819af]
F, [2019-01-11T22:04:21.405585 #17222] FATAL -- : [14c2eed0-3aae-4ab6-8142-9aa9744819af] ActionController::RoutingError (No route matches [HEAD] "/https:/mywebsite.com"):
F, [2019-01-11T22:04:21.405611 #17222] FATAL -- : [14c2eed0-3aae-4ab6-8142-9aa9744819af]
F, [2019-01-11T22:04:21.405648 #17222] FATAL -- : [14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:63:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:36:in `call_app'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `block in call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `block in tagged'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `tagged'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/request_id.rb:25:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/executor.rb:12:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] vendor/bundle/ruby/2.5.0/gems/railties-5.1.6/lib/rails/engine.rb:522:in `call'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:157:in `accept_and_process_next_request'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
[14c2eed0-3aae-4ab6-8142-9aa9744819af] /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
这是添加!
后的服务器日志至 purchase = Purchase.create!(
在收费 Controller 中:
F, [2019-01-15T21:21:12.869293 #24540] FATAL -- : [932479d4-c710-4ac6-9159-8c3fa5299adc] ActiveModel::UnknownAttributeError (unknown attribute 'uuid' for Purchase.):
这是我的 routes.rb 文件:
resources :charges
resources :purchases, only: [:show]
我已经删除了 get 'purchase' => 'purchases#show', as: 'purchase'
来自 routes.rb
因为它破坏了我的代码。
它让 URL 这样做:https://mywebsite.com/purchase.uuid
而不是这个:https://mywebsite.com/purchase/uuid
这是我的 config/environments/production.rb 文件:
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.log_level = :debug
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'transverseaudio.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'transverseaudio.com',
:enable_starttls_auto => true
}
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
end
运行后rails routes
:
charges GET /charges(.:format) charges#index
POST /charges(.:format) charges#create
new_charge GET /charges/new(.:format) charges#new
edit_charge GET /charges/:id/edit(.:format) charges#edit
charge GET /charges/:id(.:format) charges#show
PATCH /charges/:id(.:format) charges#update
PUT /charges/:id(.:format) charges#update
DELETE /charges/:id(.:format) charges#destroy
purchase GET /purchases/:id(.:format) purchases#show
最佳答案
我建议您将 ChargesController.create
包装在事务中。如果 Purchase.create
中出现某些(例如验证)错误,您最终会在 db + Stripe 中的真实交易中创建一些部分数据。此外,检查是否实际创建了 purchase
将是一个很好的改进:
if purchase
redirect_to purchase
else
render :new, error: purchase.errors
end
然后在生产 GUI 中你会清楚地看到问题是什么。
此外,在您的日志中 F,[2019-01-15T21:21:12.869293 #24540] FATAL -- : [932479d4-c710-4ac6-9159-8c3fa5299adc] ActiveModel::UnknownAttributeError (unknown attribute 'uuid ' for Purchase.):
,这可能意味着您的迁移没有应用到产品中,您只是在 Purchase
中缺少 uuid 列。
关于ruby-on-rails - 表条目在开发中工作正常但在生产中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54163578/
我有一台 MySQL 服务器和一台 PostgreSQL 服务器。 需要从多个表中复制或重新插入一组数据 MySQL 流式传输/同步到 PostgreSQL 表。 这种复制可以基于时间(Sync)或事
如果两个表的 id 彼此相等,我尝试从一个表中获取数据。这是我使用的代码: SELECT id_to , email_to , name_to , status_to
我有一个 Excel 工作表。顶行对应于列名称,而连续的行每行代表一个条目。 如何将此 Excel 工作表转换为 SQL 表? 我使用的是 SQL Server 2005。 最佳答案 这取决于您使用哪
我想合并两个 Django 模型并创建一个模型。让我们假设我有第一个表表 A,其中包含一些列和数据。 Table A -------------- col1 col2 col3 col
我有两个表:table1,table2,如下所示 table1: id name 1 tamil 2 english 3 maths 4 science table2: p
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 1 年前。 Improve th
下面两个语句有什么区别? newTable = orginalTable 或 newTable.data(originalTable) 我怀疑 .data() 方法具有性能优势,因为它在标准 AX 中
我有一个表,我没有在其中显式定义主键,它并不是真正需要的功能......但是一位同事建议我添加一个列作为唯一主键以随着数据库的增长提高性能...... 谁能解释一下这是如何提高性能的? 没有使用索引(
如何将表“产品”中的产品记录与其不同表“图像”中的图像相关联? 我正在对产品 ID 使用自动增量。 我觉得不可能进行关联,因为产品 ID 是自动递增的,因此在插入期间不可用! 如何插入新产品,获取产品
我有一个 sql 表,其中包含关键字和出现次数,如下所示(尽管出现次数并不重要): ____________ dog | 3 | ____________ rat | 7 | ____
是否可以使用目标表中的LAST_INSERT_ID更新源表? INSERT INTO `target` SELECT `a`, `b` FROM `source` 目标表有一个自动增量键id,我想将其
我正在重建一个搜索查询,因为它在“我看到的”中变得多余,我想知道什么 (albums_artists, artists) ( ) does in join? is it for boosting pe
以下是我使用 mysqldump 备份数据库的开关: /usr/bin/mysqldump -u **** --password=**** --single-transaction --databas
我试图获取 MySQL 表中的所有行并将它们放入 HTML 表中: Exam ID Status Assigned Examiner
如何查询名为 photos 的表中的所有记录,并知道当前用户使用单个查询将哪些结果照片添加为书签? 这是我的表格: -- -- Table structure for table `photos` -
我的网站都在 InnoDB 表上运行,目前为止运行良好。现在我想知道在我的网站上实时发生了什么,所以我将每个页面浏览量(页面、引荐来源网址、IP、主机名等)存储在 InnoDB 表中。每秒大约有 10
我在想我会为 mysql 准备两个表。一个用于存储登录信息,另一个用于存储送货地址。这是传统方式还是所有内容都存储在一张表中? 对于两个表...有没有办法自动将表 A 的列复制到表 B,以便我可以引用
我不是程序员,我从这个表格中阅读了很多关于如何解决我的问题的内容,但我的搜索效果不好 我有两张 table 表 1:成员 id*| name | surname -------------------
我知道如何在 ASP.NET 中显示真实表,例如 public ActionResult Index() { var s = db.StaffInfoDBSet.ToList(); r
我正在尝试运行以下查询: "insert into visits set source = 'http://google.com' and country = 'en' and ref = '1234
我是一名优秀的程序员,十分优秀!