Rails, How to render a view/partial in a model

前端 未结 10 1823
不思量自难忘°
不思量自难忘° 2020-12-22 18:55

In my model I have:

after_create :push_create

I push_create I need to render a view. I\'m trying to do that like so:

  def         


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 19:27

    the "proper" way to do this is to push an object in serialized form(json), and then have the view deal with it once the event is received. Perhaps you want to use Handlebars to render the object.

    Edit: I originally wrote about how, despite my answer, I was going to follow your example. But I just realized there is a HUGE gotcha with your approach when it comes to push notifications.

    In your problem, you are doing push notifications to one user. For me, I was broadcasting out to a set of users. So I was going to render html with a presumption of a "current_user" and all that comes with it(eg logic, permissions, etc). This is NO BUENO as each push notification will be received by a different "current user".

    Therefore, really, you need to just send back the data, and let each individual view handle it.

提交回复
热议问题