Question

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"}
Was it helpful?

Solution

If you're calling update_attributes and params[:email_blast][:mail_type] is defined, then it will be reassigned. You can always set this parameter as protected to avoid this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top