如何将数据从api传递到rails中的其他控制器?

时间:2017-11-06 10:40:20

标签: ruby-on-rails rails-flash wisper

我有一个接受并保存数据的api。

我想将当前用户界面上的数据作为flash获取怎么做?

我尝试wisper gem并且不支持Flash提醒。

  

$ 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

0 个答案:

没有答案