我的 mail_type 属性正在更新..但我不明白为什么?
def update
debugger
@email_blast = EmailBlast.find(params[:id])
if @email_blast.update_attributes(params[:email_blast])
debugger
# changes mail_type here
flash[:notice] = 'Email Blast Saved.'
if params[:id] == "1"
Delayed::Job.enqueue MassEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "2"
Delayed::Job.enqueue OrgBlast.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "3"
Delayed::Job.enqueue MagicEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "4"
Delayed::Job.enqueue OrgMagicEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
end
redirect_to edit_admin_email_blast_path(params[:id])
end
end
这有多奇怪?传递此控制器代码后, @email_blast.mail_type 将更改为 "card_holder" 。为什么会发生这种情况?第一个调试器上的参数返回:
(rdb:407) @email_blast = EmailBlast.find(params[:id])
#<EmailBlast id: 3, subject: "HQMagic Email", body: "asdfasdfasdfasdfas<br />\r\nd<br />\r\nfas<br />\r\ndf<br...", mail_type: "magic_email", created_at: "2010-10-28 14:57:48", updated_at: "2010-11-04 20:51:45">
第二个:
{"body"=>"asdfasdfasdfasdfas<br />\r\nd<br />\r\nfas<br />\r\ndf<br />\r\nasdf<br />\r\nas<br />\r\ndf<br />\r\nasd<br />\r\nfasd<br />\r\nfa<br />\r\nsd<br />\r\nfasd", "mail_type"=>"card_holders", "id"=>"3", "subject"=>"HQMagic Email"}
def update
debugger
@email_blast = EmailBlast.find(params[:id])
if @email_blast.update_attributes(params[:email_blast])
debugger
# changes mail_type here
flash[:notice] = 'Email Blast Saved.'
if params[:id] == "1"
Delayed::Job.enqueue MassEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "2"
Delayed::Job.enqueue OrgBlast.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "3"
Delayed::Job.enqueue MagicEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
elsif params[:id] == "4"
Delayed::Job.enqueue OrgMagicEmail.new(params[:email_blast][:subject], params[:email_blast][:body])
end
redirect_to edit_admin_email_blast_path(params[:id])
end
end
How strange is that? Once this controller code is passed, @email_blast.mail_type gets changed to "card_holder" . Why would that happen? the Params on the first debugger return :
(rdb:407) @email_blast = EmailBlast.find(params[:id])
#<EmailBlast id: 3, subject: "HQMagic Email", body: "asdfasdfasdfasdfas<br />\r\nd<br />\r\nfas<br />\r\ndf<br...", mail_type: "magic_email", created_at: "2010-10-28 14:57:48", updated_at: "2010-11-04 20:51:45">
And the second :
{"body"=>"asdfasdfasdfasdfas<br />\r\nd<br />\r\nfas<br />\r\ndf<br />\r\nasdf<br />\r\nas<br />\r\ndf<br />\r\nasd<br />\r\nfasd<br />\r\nfa<br />\r\nsd<br />\r\nfasd", "mail_type"=>"card_holders", "id"=>"3", "subject"=>"HQMagic Email"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您调用
update_attributes
并且定义了params[:email_blast][:mail_type]
,那么它将被重新分配。您始终可以将此参数设置为受保护以避免这种情况。If you're calling
update_attributes
andparams[:email_blast][:mail_type]
is defined, then it will be reassigned. You can always set this parameter as protected to avoid this.