0

I have a api which accepts and saves data in rails.

I would like to get that data on the current UI as flash how to do it ?

I tried to wisper gem and flash alerts are not supported.

$ 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

Reference for detail discussion, https://github.com/krisleech/wisper/issues/165

Anand
  • 6,457
  • 3
  • 12
  • 26
Kiran Patil
  • 421
  • 1
  • 5
  • 18
  • are you looking to auto update views with out calling api?? Then might be action cable is what you are looking for. Here is a good example https://blog.heroku.com/real_time_rails_implementing_websockets_in_rails_5_with_action_cable – Narasimha Reddy - Geeker Nov 06 '17 at 12:16
  • This isn't how Ruby/Rails works. The listener, `SmsListener`, can't see in to other objects. That is why the `flash` is not defined, it is part of the controller, not the listener. The [Wisper wiki](https://github.com/krisleech/wisper/wiki) has a lot of examples. – Kris Nov 07 '17 at 13:34

0 Answers0