ruby-on-rails - Nexmo - Rails 中未定义的方法 send_message

标签 ruby-on-rails nexmo

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

直到几天前,代码运行良好。
enter image description here

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/

相关文章:

ruby-on-rails - Rails 4 x postgresql:ActiveRecord::InvalidForeignKey

ruby-on-rails - 在设计注册 Controller 中添加用户配置文件

ruby-on-rails - Rails - Postgres - 按关联对象计数分组

audio - Websocket丢帧?

grails - Grails和Nexmo插件

grails - 将Grails连接到Nexmo插件时出错

ruby-on-rails - 在 Rails 中总是使用整数来定义外键?

ruby-on-rails - 如何获取列表中具有相同类别的所有项目