Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6242411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:57:01+00:00 2026-05-24T11:57:01+00:00

In a Rails app I’ve used Faye (Rack adapter) for push notifications (for chat).

  • 0

In a Rails app I’ve used Faye (Rack adapter) for push notifications (for chat).

I want to use Faye for another use case (more push notifications) but I can’t seem to figure it out.

In my app a model can be created from a background job so I want to refresh one of my views (say the index action) when the model gets created.

Like so:

app/models/post.rb

class Post
    include Mongoid::Document

    after_create :notify_subscribers

    private
    def notify_subscribers
        Faye::Client.publish("/posts")
    end
end

app/views/posts/index.html.erb

<%= subscribe_to(posts_url) do %>
   uhh what do I do here? ajax call to refresh the whole page??
<% end %>

So is publishing the notification directly from an after_create callback a good idea
and when I get a message from the Faye server how to I go about implementing the “update”?
Do I just do an AJAX call to reload the data from the server? That seems like it would be slow.

Further I want to use something similar for updates to the model (say a user added some comments or the author changed the content) so thrashing the DB all the time doesn’t seem like a good plan…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:57:02+00:00Added an answer on May 24, 2026 at 11:57 am

    First of all, yes, publishing the notification with after_create is fine. What you should do in your notify_subscribers method is to publish all relevant information about the new post that you want to use in the client so that you don’t have to make another unnecessary AJAX request when the notification is received.

    So, for instance, if the title and content of the post are relevant for the user to see immediately after it gets created, you would do something like:

    def notify_subscribers
      client = Faye::Client.new('http://localhost:3000/faye')
      client.publish("/posts/new", {
        'title' => self.title,
        'content' => self.content
      })
    end
    

    …and then, in the view, you would probably use jQuery to use the data about the new post which you receive from the server. Rails code won’t help you here. E.g. you would do this (assuming you’re using jQuery and have included faye.js in your header):

    <script type="text/javascript">
    $(function() {
      var client = new Faye.Client('http://localhost:3000/faye');
      client.subscribe("/posts/new", function(data) {
        /* do whatever you need with data */
      });
    });
    </script>
    

    Finally, if somehow the information you want to transfer is too complex to transfer as part of the notification, or you already have existing AJAX processes for updating your view, you could just publish the post’s ID and trigger an AJAX call with jQuery in the subscribe callback function. I’d recommend this only if necessary though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Rails app that uses Pusher to use web sockets to push
In my rails app I use the validation helpers in my active record objects
Rails app, learning CoffeeScript and Backbone.js: Uncaught TypeError: Cannot use 'in' operator to search
The first rails app I wrote used the hand-rolled authentication from railstutorial . For
I have a Rails app that repeatedly talks to another Web server through a
My rails app has two pages based on two controllers/ views/ models..both controllers use
My rails app runs fine on my local Ubuntu machine, but when I push
In my ruby on rails app I have to use recursion to render nested
I have a rails app that I enjoy developing on a sever much more
My rails app uploads all users photos to a folder /uploads/photos/. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.