Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Posted in Was wondering id there is a way i can simply this ...

You can set up the association on the user to has_many through:

class User
  has_many :brands
  has_many :articles, through: :brands
end

And then you can access them directly and it will be auto-scoped for you:

current_user.articles

The performance on that is probably similar to writing and committing records one by one on a csv import vs writing a transaction and committing everything at once. You'll have a lot more speedups writing everything in bulk.

Are you sure that the scope thing is actually going to solve your problem in Rails 5? I thought we determined that wasn't going to help as it wasn't related to your tenant issue?

Posted in Pull data from another table in a lookup

Jacob's the one that did the hard work though. I just had to tweak his answer a little bit. ;) He's the one that deserves cake 🍰.

Posted in Pull data from another table in a lookup

I believe you want @articles = Article.where(brand_id: brand_ids).includes(:brand) which will load that association. Pretty close to what Jacob said, but you need to reference the association in the includes.

Then when you print out the articles, you can say

<% @articles.each do |article| %>
  <div>
    <%= article.brand.name %>
  </div>
<% end %>

This should be efficient because it will make two queries and preload the brand association on each article.

I don't believe there are any necessary changes for Heroku. You should be able to just deploy it, making sure that your allowed request origins match the domain you're running on.

Posted in Direct File Uploads to S3: Part 1 Discussion

Yeah, you'll probably want to crop the pictures to a standard size in the processing phase.

The problem with using only CSS is that your user might upload a 10MB image and you don't want all your users having to download that, so it's best to always crop to a few standard sizes to prevent that from happening so your site can continue being fast.

You can set like a standard avatar size (say 100px x 100px) and then resize it with CSS so the image can be displayed at various sizes but reused from the browser cache.

Posted in In-App Navbar Notifications Discussion

React stuff is coming soon! :)

Posted in Direct File Uploads to S3: Part 1 Discussion

Like Janko said, you can do uploads to your server or to S3 with Shrine just like you would with Carrierwave. Shrine can do everything you could do in Carrierwave (and better in my opinion) so I would recommend using it for everything.

My recommendation would be to never setup your files to upload to your server's filesystem unless it's a hobby project. You'd have to migrate the files once your harddrive is full and that's no fun.

With S3, you have two options:

1. You can upload your files to your Rails server and Shrine will send them over to S3.
2. You can directly upload files to S3 like I showed in this video.

The first option is simpler because you just have to configure Shrine to do the upload to S3.

Direct uploads use your user's browser to upload straight to S3 and it skips your server. That means the direct uploads are faster, but they're a fair amount more work (like you see in the video).

The simplest and best option to get started is to simply use S3 (#1) for both the cache and store for Shrine. You don't have to build any of the Javascript stuff right away and all your uploads will be saved to S3. When you're ready, you can add in the Javascript portion for direct uploads in order to make them upload faster. Since you'd already be using S3, it's a simple change this way.

Posted in Group Chat with ActionCable: Part 7 Discussion

It's missing setting the last_read_at when you join a new channel. Should be in the chatroom_users controller.

Posted in Group Chat with ActionCable: Part 7 Discussion

Check out the code on Github, we fixed that bug in the repository. 👍

I'm a few days behind catching up on the forum. Great to see you got it working! Having the quantity being passed over sure helps. :) Took a while to debug, but I bet it feels good to have figured it out!

Ah yep. Hmm, so I guess then the thing to do is debug why @chatroom_user is set to nil instead of a record. Does your chatrooms#show set the @chatroom_user record? https://github.com/gorails-screencasts/chatrooms/blob/master/app/controllers/chatrooms_controller.rb#L14

Posted in Saved messages as HTML

Yeah, that was one of those weird things that jQuery does. It'll work as you might think, but not completely. If you were writing this with plain JS, you'd use the same code as I did in my solution basically. No funny business that way.

Posted in Saved messages as HTML

Hey Martin!

This is actually a small bug you find in the JS for that episode. The append() in handleChange works fine for adding plain strings, but not HTML ones to the value of the inputs. If you change the append line to the following, you'll see that it works just fine:

    comment_body.val comment_body.val() + saved_message_text

This is a better way of adding text to a field, where you set the value to the old value plus your new text. Append seems to do that, but not when there is html that you want to add for some reason.

I updated the repository to fix that bug as well. 👍

Posted in Group Chat with ActionCable: Part 1 Discussion

Hey! I believe that should be just

><% current_user.chatrooms.each do |chatroom| %>

because we didn't build anything called "public_channels" I don't believe.

You can find that line in the github repo here: https://github.com/gorails-...

I believe I introduced a bug related to this at one point which you might be running into. Check out the code on Github in the notes on the episode and you might spot the fix I introduced. Can't remember exactly what it was.

Ah, so the error is saying your @chatroom_user record is nil (didn't get saved for some reason) and therefore your last_read_at didn't work. Slight different than the error I was originally thinking of. Check your @chatroom_user gets set properly in the controller and why that might not be set.

Yep, that looks right. Your Rails app doesn't seem to know that exists though which means there's some discrepancy. Maybe try restarting your Rails server in case it didn't pickup the migration or there might be a typo somewhere I'm not noticing.

Or maybe you've got a different error than the one I'm assuming you've got. Can you paste the full error?

If it's a no method error, make sure you ran the migration to add that column to the ChatroomUser model. The no method error usually comes up when a column doesn't exist that you try to access.

Actually ice_cube has yaml, hash, and ical exports so that probably makes it a better solution at the moment over Montrose for this purpose. I'll probably try to cover both and not the differences between them.

Ah yes, that's one of those special cases that can be hard to solve. I'll try to cover that use case in the episode or a follow up if I can. I think what you'd want to do in that case is to save that date like a non-recurring event and then add an exception to the recurring events for to skip that date. Kind of confusing, but should do the trick assuming they can handle that.

Looking forward to covering this finally. I should have done this months ago. ;)