【发布时间】:2014-07-28 06:51:48
【问题描述】:
我正在尝试在创建交易时发送邮件。邮件的内容包含交易的开始日期、结束日期、年数。当使用传递方法尝试此操作时,邮件包含所有信息。但是当我尝试使用延迟工作时,我无法获得年数。为什么?有人帮帮我吗?
def create
@transaction = Transaction.new(params[:transaction])
if transaction.start_date.present?
transaction.save!
Mailers.delay.transaction_created_notification(@transaction)
end
transaction.save!
Mailers.delay.transaction_created_notification(@transaction)
查看
<h3>The Transaction has been created.</h3>
<p> Transaction start date: <%= @transaction.start_date %></p>
<p> Transaction end date: <%= @transaction.end_date %></p>
<p>No of years: <%=@transaction.num_years %> </p>
日志文件
Started POST "transaction" for 127.0.0.1 at 2014-07-25 16:02:10 +0530
Processing by TransactionController#create as HTML
Parameters{"utf8"=>"✓","authenticity_token"=>"ziUJghnsfUjuWA5ar17lgZ0QaOz0Psm3L8lN0wXa7tY=", "transaction"=>{ "start_date(1i)"=>"2014", "start_date(2i)"=>"7", "start_date(3i)"=>"1", "num_years"=>"10"}, "commit"=>"Create Transaction"}
(0.1ms) BEGIN
SQL (0.3ms) INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at``handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2014-07-25 10:32:10', NULL, '--- !ruby/object:Delayed::PerformableMailer\nobject: !ruby/class \'Mailers\'\nmethod_name: :transaction_created_notification\nargs:\n- !ruby/ActiveRecord:Transaction\n attributes:\n id: 435\n school_id: 371\n start_date: 2014-07-01\n end_date: 2024-06-30\n created_at: &1 2014-07-25 10:32:10.446748247 Z\n updated_at: *1\n', NULL, NULL, NULL, 0, NULL, '2014-07-25 10:32:10', '2014-07-25 10:32:10')
(40.6ms) COMMIT
Redirected to http://sat.lvh.me:3000/Transaction/371
Filter chain halted as # <Proc:0x0000000bd6d408@/home/kavi/newproject/app/admin/Transaction.rb:40> rendered or redirected
Completed 302 Found in 108.4ms (ActiveRecord: 68.8ms)
【问题讨论】:
-
查看日志文件中处理程序的序列化数据,您传递的参数似乎是
Contract类型,而不是Transaction。除非您在生成日志后更改了代码。我们能看到交易和合约的模型吗? -
我现在更新了正确的日志文件。