0
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"}
4

1 回答 1

2

如果您正在调用update_attributes并且params[:email_blast][:mail_type]已定义,那么它将被重新分配。您始终可以将此参数设置为受保护以避免这种情况。

于 2010-11-04T21:27:04.613 回答