我的 mail_type 属性正在更新..但我不明白为什么?

发布于 2024-10-01 09:31:29 字数 1635 浏览 1 评论 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"}
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2024-10-08 09:31:29

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文