Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2020
What would you like to do?
Push Notifications from the Rails console
Rpush.embed # to deliver push notifications in the Rails console on notification save
# Selecting the mobile device that'll receive the notification:
greg = User.find_by(login: "greg.blake")
devices = greg.mobile_devices
@mobile_device = greg.mobile_devices.last
# Sending a notification to the device
n =; =;
n.device_token = @mobile_device.device_token;
n.alert = Faker::Matz.quote;
apns_topic =; = {'headers' => { 'apns-topic' => apns_topic }}; # This delivers the push notification
# If returns false, you can see what went wrong with n.errors.full_messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment