is it possible to send a directed flash message in rails? - ruby-on-rails

this is kind of a dumb question, but is it possible to send a
flash[:success]
directed to a certain user other than the current user on the screen? in one of my controllers i have
if #article.up_votes.count > 10
flash[:success ] = 'something'
end
is it possible to send that flash to the owner of the article? as opposed to my own screen? or is there another way to do this?
i tried looking through
http://api.rubyonrails.org/classes/ActionDispatch/Flash/FlashHash.html#method-i-notice
but couldn't find any method that would help. maybe i am reading it wrong? is there a way to achieve the same effect then?
thank you...

Not using flash, you'd have to try something else, there are lots of ways to go about it, but flash isn't one of them. Well, you could still use flash, but it wouldn't be to send from one user to another, you could cause a flash message to appear for the user being notified.
First thing to figure out is how do you notify the other user, when would he get that notification, do you want him to get notified anytime he using your site? Or only if he does something specific on your site?

For what I know the best way to go, maybe the only way actually is push notifications. There are many ways to achieve this but I think faye should be the easiest.
See this screencast to understand it and later. You want to have a channel for each user so it will be the one to get that message. Further search for private pub so nobody's can listen to others channel
http://railscasts.com/episodes/260-messaging-with-faye
http://railscasts.com/episodes/316-private-pub

As ismaelga mentioned I also think push notifications is the way to go (WebSockets).
In addition to Faye you can use a hosted solution called Pusher (pusher.com).
Here is a really short description about how Pusher can help you. Bassically all users using your application listens for messages on a WebSocket-server (through JavaScript). In this case Pusher. You can then send messages to Pusher via your Rails application. When you send a message to Pusher, all users will instantly be notified about the new message via JavaScript (through the WebSocket). To only notify a specific user you can use Pusher's "private channels"-feature.
Pusher have some really good documentation on how to use their service: http://pusher.com/docs/javascript_quick_start
This picture (taken from Nettuts+) might also give you a better understanding of how Pusher works: http://d2o0t5hpnwv4c1.cloudfront.net/1059_pusher/pusher_websocket.png
Hope this helps a bit.

Related

Changing messages on Slack

So I'm attempting to change a message in slack through my slackbot at the end of a chain of events. I'm able to change it for the first few instances, but I'm not able to do the very last one. I'm 99% sure that it is because I have reached the 5 interactions limit since I am indeed going through 5 interactions with the user prior to my final message. If this is the case, is there a way to change a message without server responses? I ask because the last message is simply a thank you message to the user for participating. It doesn't actually require any input from data on the server to accomplish. I feel like I read about doing it somewhere, but for the life of me I cannot find it again. Any help or links would be greatly appreciated!
EDIT: The user is interacting with buttons through interactive messages to respond to some questions. The current method of updating messages are with chat.update and setting "response_type": "ephemeral" within the json params that I am sending.
An alternative method to using chat.update is to simply reply with the message to the request from Slack. This will replace the existing message by default. It has no limit that I am aware of, so it solves your problem.
This works great with slash commands and interactive messages.
See here for more details.

How do I implement bubble notifications in rails?

I already have a feed with the public_activity gem . However, I want to have a facebook-like on-site notification system where the user can see a number in red background, representing the new notifications concerning him.
I have never implemented such a thing and I am not sure how to go about it.
Most answers about Rails notifications will recommend using Mailboxer, public_activity, and any other messaging gem but nothing about the dynamic real-time facebook like notification that easily alarms you of the new notifications with the number and links.
Thanks for your help !!!.
You can use polling with a JS library like jQuery. There is another good example that can be followed.
The main focus would be making an ajax request after a specific time and check for the results and repeat the process.

Rails 3 - Send Mails, Request request progress using ajax

i want to use Rails 3 to send a relatively large amount of emails to a couple of recipients. The email functionality is basically implemented, so that's not the matter here.
My problem is that this amount of emails is sent relatively slow. So i want to give the user a little feedback using AJAX. Now this feedback should be unique for each user of course. My first thought was to create a helper class which sends these mails using a thread and a method for requesting the progress. Problem is, how can I make this functionality unique to each user per session?
I'm new to Rails and have absolutely no idea, I think some kind of Stateful Session Bean (like EJB) should make it. Does Rails or one of its addons offer something like that?
Sorry for my english, it's a bit rusty. :)
may be this help sidekiq_mailer
this adds to your ActionMailer classes the ability to send mails asynchronously.

Xcode chat app, creating dynamic views - a little lost

Am just about to start doing an iphone application which is supposed to have a multi user private chat. Something like facebook style, where the user has a list of friends and he can chat with them independently. I just need a little direction here
If i have a list of users, let's say i create individual views for the chat, how can I handle these views? If jim is chatting with dick and jane, there should be 2 views, each for one chat window right? Are there any references that i can use.
I am looking for references in socket programming where i can push messages to the user from the server. I have been looking but could not find anything helpful.
If i try to update the user's chat window using local notifications, lets say request data every couple of seconds, will that be battery draining?
I would really like some direction here, i do not want to start something just realize its the wrong way.
Any help is highly appreciated
Those all sound like design decisions. For example, do you want to display each user's messages in a separate view? That's entirely up to you.
You'll want to read about iOS Push Notifications.
If you mean that you intend to poll some server for updates, then yes, that will use a lot of battery. This is exactly the sort of situation that the push notification system was created to help you avoid.

Best practices on processing email sent to app specific address in rails?

We would like to implement a feature by which users could send an email to an application specific address and we will parse the message and take certain actions on it, similar to 37signals's backpack (and probably some of their other apps).
If anyone has done something similar, could you fill me in on how you did so? I'm unsure on how to, at a high-level, 'import' the email into the app so that I could process it.
Thank you.
I have recently implemented that exact functionality in rails. I would advice you to look at the 'Receive E-mail Reliably via POP or IMAP' in the the Advanced Rails Recipes book.
I've personally found that the best source for getting this up and running and it explains how to do far better than I can. Good luck which ever way you choose to do it :)
Here's how I fetch from a POP server:
require 'net/pop'
pop = Net::POP3.new('mail.yourdomain.com')
pop.start(account, password)
pop.each_mail do |m|
email = TMail::Mail.parse(m.pop)
email.base64_decode
OttoMailer.process_email_in(email, m.unique_id)
m.delete
end
pop.finish
Why not run a Ruby SMTP mailserver, which will receive the mails via port 25, and then you can parse/interpret etc. as you wish ?
(I say Ruby since that's how you've tagged your question)
An alternative solution is to run procmail (or similar), pattern match on the subject, and then invoke scripts (configured in the .procmailrc file). However that may not scale so well for large volumes of mail.
ActionMailer can receive e-mails as well as send them! I don't remember how this is done but if you look at the documentation you can see it there. But from memory the e-mail gets piped through procmail into a script in the script directory.
There seems to be a book on the subject as well.
Good luck! :)

Resources