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"}
答案 0 :(得分:2)
如果您正在调用update_attributes
并且params[:email_blast][:mail_type]
已定义,则会重新分配。您始终可以将此参数设置为protected以避免此情况。