我正在尝试使用 nexmo gem 发送短信,

直到几天前,代码运行良好。
ruby-on-rails - Nexmo - Rails 中未定义的方法 send_message-LMLPHP

def send_sms
    @number = params[:number]
    @nannytel = params[:phone]
    nexmo = Nexmo::Client.new(
    key: 'xxxxxxx',
    secret: 'xxxxxxx'
    )

    notification = "The contact number is following #{@nannytel}"

    response = nexmo.send_message(
      from: "SENDERID",
      to: @number,
      text: notification
    )

    if response['messages'].first['status'] == '0'
    flash[:success] = "Yayy! 🎉 We just sent you details for the nanny 😍"
    redirect_to root_path
    else
    flash[:alert] = "Uh Oh! Something went wrong, please try entering your number again"
    redirect_to root_path
    end
  end

以上是 pages Controller 中的方法

最佳答案

请修改以下代码

response = nexmo.send_message(
  from: "SENDERID",
  to: @number,
  text: notification
)

作为
response = nexmo.sms.send(
  from: "SENDERID",
  to: @number,
  text: notification
)

根据 documentation 版本 5.0.2 需要进行上述更改

或者

使用版本 4.8 而不是 5.0.2
gem 'nexmo', '4.8'

关于ruby-on-rails - Nexmo - Rails 中未定义的方法 send_message,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49586225/

10-11 17:43