0

我有一个 api,它接受并将数据保存在 rails 中。

我想在当前 UI 上获取该数据作为 flash 怎么做?

我试过了wisper gem,但不支持闪光警报。

$ cat app/controllers/api/v1/sms_controller.rb

class API::V1::SmsController < ApplicationController

  def incoming_sms
   contact = LocationMessage.new
   contact.number = params[:number]

   message = params[:message]

   if contact.save 
          render :json =>"Location Message saved", status: 201
   else
          render json: { errors: contact.errors}, status: 422
         end
   end
end



Class LocationMessage < ApplicationRecord
  include Wisper::Publisher

  after_save :publish_creation_successful

  def publish_creation_successful
    broadcast(:emergency_location_creation_successful)
  end
end



def new
    flash[:notice] = "coollllll blah blah"
    @incident = Incident.new
     Wisper.subscribe(SmsListener.new)
end

  class SmsListener
    def emergency_location_creation_successful()
      flash[:notice] = "Location is saved"
    end
  end

详细讨论参考,https://github.com/krisleech/wisper/issues/165

4

0 回答 0