Activity
Yeah, data-confirm is just a generic attribute you can use on any clickable item, not just delete links. That should work fine.
Turns out it doesn't have access to the session, so you can't use that. http://edgeguides.rubyonrails.org/action_cable_overview.html#notes
You can probably do the signed cookies like the article there mentions as an alternative. That's how things work with Devise.
cookies.signed[:user_id]
instead but also has to change in your controllers as well.
Update: Here's an example on StackOverflow: http://stackoverflow.com/questions/37671504/getting-authlogic-to-work-with-actioncable
So you set your user id in the session
. Just use that to look up the user for the websocket:
def find_verified_user
if current_user = User.find(session[:user_id])
current_user
else
reject_unauthorized_connection
end
end
Thanks Emmanuel! I appreciate it a lot and you're right, we're always learning especially with how fast this industry changes! :D
Hmmm, double check that you restarted nginx and that went correctly. If so, it should pick that up.
Posted in Does anyone have tips on setting up redis and sidekiq on a Digital Ocean ubuntu 16.04 droplet?
Yeah, there's a few options like that. I like not having to add another dependency, plus this is nice if you're already us it to run things like Redis, etc.
Posted in Does anyone have tips on setting up redis and sidekiq on a Digital Ocean ubuntu 16.04 droplet?
Basically at this point now, you'll need to use systemd to manage Sidekiq. It will make sure it starts or if it dies, it will restart it. This is nice, but kind of confusing sometimes how to get it setup.
I have this in /etc/systemd/system/sidekiq.service
and you can enable it and manage it using the commands at the top there.
#
# systemd unit file for CentOS 7, Ubuntu 15.04
#
# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Run:
# - systemctl enable sidekiq
# - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process. Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description=sidekiq
# start us only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
After=syslog.target network.target
# See these pages for lots of options:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html
[Service]
Type=simple
WorkingDirectory=/home/deploy/myapp/current
# If you use rbenv:
ExecStart=/home/deploy/.rbenv/shims/bundle exec "sidekiq -e production"
User=deploy
Group=deploy
UMask=0002
# if we crash, restart
RestartSec=1
Restart=on-failure
# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
Not that you'll need to change the WorkingDirectory
option for the location of your app and this assumes you're using rbenv
on your server for running Ruby.
This setup is for only accepting tokens to authenticate on the API. You can just pass over the Authorization header in Postman to test it out. You'll need a valid token, but just pass in "Authorization: bearer YOURTOKEN" as the header and that should do it.
Btw, the other episode I posted today shows how you can take this code and add it as a Devise strategy so you can use tokens to authenticate with Devise alongside cookies. Check that one out so you can see how to use Devise with it. :)
Posted in Slack forum notifications
In Slack, just add yourself to the #gorails-forum
channel. 💪
Posted in How do I send Prawn pdf via email
Just like you would do with sending any other email. You can read more on the guides page: http://guides.rubyonrails.org/action_mailer_basics.html
Posted in How do I send Prawn pdf via email
Hey Neil!
Attachments are pretty easy. You use the attachments
method on the email and give it a file object.
class ReferralMailer < ActionMailer::Base
def referral(recipient)
attachments['referral_form.pdf'] = BefriendingReferralForm.new(@current_referrer).render
mail(:to => recipient, :subject => "New account information")
end
end
Since you're rendering your own file, you just pass that in and Rails should take care of the rest.
Posted in Subscriptions with Stripe Discussion
Yep, this is because Turbolinks 5 works differently than the previous one where you could use jquery.turbolinks to enable all your standard jQuery ->
code to work as expected. Thanks for sharing the reminder with everyone!
Posted in How do I parse this JSON output?
Hey Stan!
You can do a pretty simple select and map to get the array of text strings here:
irb(main):002:0> @output.select{ |i| i["type"] == "Person" }.map{ |i| i["text"] }
=> ["Gloria Etting", "Betsey Cushing Roosevelt Whitney", "Emlen Etting"]
Basically the select
filters the list, and map
transforms the results from an array of hashes into an array of just the text
attribute values. Then you can loop through that list and print them out in your erb.
🤘
Posted in Slack forum notifications
It does! If anyone wants to join us in slack, the #gorails-forum channel has all the notifications now. 🤠
Posted in Slack forum notifications
Just testing out slack forum notifications.
Like Jacob said, that would be up to your implemenation.
find_verified_user
just needs you to return the User object. That's what you get from warden, so your implemenation will be similar, just however you retrieve the User object in your setup and that should do the trick.
Posted in Live Stream Video w/ Rails
I don't think you need Flash for anything these days. Also keep in mind that HTTP streaming can be used to describe streaming HTTP responses, not necessarily video. For example, you could use HTTP streaming to send realtime updates for a chatroom (before websockets were the better solution). HLS is similar to MPEG-DASH in that it's a video streaming protocol that uses HTTP. Kind of confusing stuff.
http://weblog.rubyonrails.org/2011/4/18/why-http-streaming/
https://en.wikipedia.org/wiki/HTTP_Live_Streaming
Then there's all this WebRTC stuff that's very similar, but another rabbit hole to understand. Apple doesn't support any of the WebRTC things yet, so you have workarounds for that as well I believe.
I feel like it's gonna take a lot of reading to get my head wrapped around all this, but it's some really neat stuff. I'm super fresh to all this stuff, so my descriptions of it could be way off as well. :)
That's great to hear! :D And I agree, it's a tough one to wrap your head around the first time.
Good catch, forgot to push. Just did it now!
Posted in Live Stream Video w/ Rails
I don't know too much about it, but most of that won't be going through Rails or ActionCable. You want to be sending raw data over the wire, so you wouldn't be using WebSockets or Rails for that. WebRTC is designed for this, but Javascript in the browser so it lives outside of Rails / ActionCable.
Really if you want to do live streaming, I'd use a service like https://www.twilio.com/video or https://tokbox.com/ for powering it.
I haven't done this before, so I can't relaly make a good screencast on it for you just yet. At some point I'd like to, but it's a complex topic so it'll probably take a while when I do get around to diving in.