Chris Oliver

Joined

290,800 Experience
86 Lessons Completed
298 Questions Solved

Activity

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

Posted in Deploy Ubuntu 16.04 Xenial Xerus Discussion

Hmmm, double check that you restarted nginx and that went correctly. If so, it should pick that up.

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.

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.

Posted in JSON Web Token Authentication From Scratch Discussion

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. :)

Posted in Comments With Polymorphic Associations Discussion

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.

Posted in Stripe gems: Koudoku or Payola

Yeah I think a lot of people do the same thing with Devise, however, it's got a great design so you can dive into the guts of it and make changes really easily. It also doesn't enforce much of anything upon your application, but it's easy to misunderstand that when you're new to the gem.

Posted in Stripe gems: Koudoku or Payola

Hey Mark,

I've personally always found it easiest to just build the Stripe integration myself. I've tried a couple of these gems and often found I was boxed into the way they do things which I could break out of, but at that point I'd basically not be using their gem that much.

You can always try the gems in a sample app and see how the integration goes before you put it in your real project.