gpt4 book ai didi

ruby-on-rails - 为什么我得到 "undefined method ` 编码'”?

转载 作者:行者123 更新时间:2023-12-04 07:32:37 25 4
gpt4 key购买 nike

为什么我得到“未定义的方法‘编码’”?
我怎样才能解决这个问题?

错误信息

NoMethodError (undefined method `encoding' for #<Array:0x000000218f61e8>):
app/controllers/messages_controller.rb:255:in `deliver'

messages_controller.rb
# coding: UTF-8

class MessagesController < ApplicationController

deliver
users = User.confirmed.order("created_at ASC")

@users_emails = []
users.each do |user|
@users_emails += [user.email]
end

subject = params[:messages][:subject]
body = params[:messages][:body]

CallMailer.call_email(@users_emails, subject, body).deliver <= This is line 255
end

end

mailers/call_mailer.rb
# coding: UTF-8

class CallMailer < ActionMailer::Base

default :from => "dont-reply@example.com"

def call_email(users_emails, mesesage_subject, mesesage_body)
@users_emails = users_emails
@mesesage_subject = mesesage_subject
@mesesage_body = mesesage_body
mail(
:bcc => @users_emails,
:subject => @mesesage_subject,
:body => @mesesage_body) do |format|
format.html
end
end

end

最佳答案

我发现您为 bcc 获得了正确的数组,可能您输入了一些错误的电子邮件地址。

当电子邮件地址在@ 之前包含一个点时,例如 test.@test.com,并且作为数组的一部分提交时,您将获得一个未定义的数组方法“编码​​”。该错误仅出现在 Ruby 1.9 中,并且仅本地址作为数组提交时才会出现。

尝试这个

def call_email(users_emails, mesesage_subject, mesesage_body)
@users_emails = users_emails
@mesesage_subject = mesesage_subject
@mesesage_body = mesesage_body
mail(
:bcc => @users_emails.join(','),
:subject => @mesesage_subject,
:body => @mesesage_body) do |format|
format.html
end
end

关于ruby-on-rails - 为什么我得到 "undefined method ` 编码'”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com