Chris Oliver

Joined

234,920 Experience
17 Lessons Completed
256 Questions Solved

Activity

Posted in Memoization Discussion

Thanks for your support Ken! :D

Posted in File Uploads with Refile Discussion

I'm not sure why this isn't the default. It's a really important thing for managing a large set of files, so you'd think this was already in there.

I see a prefix option for the library that allows you to do this, but I don't see much information on how you'd set that dynamically.

This is the prefix option I'm talking about. You would need this to be set dynamically each time a different file type was uploaded which I don't know is very easy to customize.

Refile.store = Refile::S3.new(prefix: "store", **aws)

It's probably worth opening a Github Issue on the Refile to ask about this and see if there's currently a way to do that or if a patch needs to be made to support it.

Posted in Using Webhooks with Stripe Discussion

Have you printed out the result from this line? invoice.lines.data[0].plan

I'm wondering if it isn't returning a hash, but some other type (like maybe the plan is just the string ID instead and it doesn't auto-include the nested plan attributes). I don't know off the top of my head, but I'd recommend checking that out and seeing what you get.

Posted in Building a multi-location app in rails

This isn't entirely related, but did you know you can actually use multiple subdomains? It's rare and makes things more complicated, but you can do en.newyork.example.com if you wanted. I wouldn't recommend it, but fun fact. :)

I wouldn't recommend using multi-tenancy for this, but rather just scoping your results.

You'll want to setup the routes so that the first part of the URL is matched for the location, then you can lookup a Location record in your database, and scope all your controllers to @location. That way you'll get the effect of multi-tenancy but without the trouble by just making sure you reference @location.posts for example instead of Post.all.

Plus you won't have to worry about single sign-on because that only matters between separate domains generally.

Posted in JRuby on Rails and Java dependency management

I actually haven't used JRuby much at all personally, but I'm really curious about how this works as well. JRuby is a really fantastic project especially when you need to integrate with existing Java libraries.

Posted in integrating analytics

Analytics is a super good topic to cover. There's so much of it to take into account with all the tough questions of: Should I track this in the frontend or the backend? What should I call it? How should I save the metadata? How can we design this so it'll be valid data for a long time?

Also this is an awesome list of other production-ready topics. A lot of this is stuff I end up taking for granted, but absolutely needs to be in some screencasts.

Posted in Subscriptions with Stripe Discussion

Oh good question. Subtle thing here, but very important. The reason it's in the controller is because you're probably going to use the same logic to do authorization in the controller actions. You can easily expose the method as a helper using helper_method for the views, so this allows you to write it in one place and use it in both the controller and the views.

You'll have to make sure to modify your theme to use the image_tag or asset_url helpers in the views to point to the correct version of the image when it's compiled for production. There's also an asset-url helper for CSS that you'll want to use for any images referenced in the CSS.

Rails compiles these assets and the urls for them can change in production so you must use these helpers when you reference assets. That's the main modification needed to most themes.

You can do that, but you can also just use your normal text editor to create and edit the file. Macvim is just what I use.

Posted in Setup Ubuntu 14.04 Trusty Tahr Discussion

Thanks for much for that Zachary! :)

Posted in Multitenancy with the Apartment gem Discussion

Yep, I'm sure it can. You may have to build a custom handler for it based on their Subdomain one, but definitely could work. Check their docs / Github issues for more on it as I haven't done that before so I don't know the details of what you'll need.

Posted in Subscriptions with Stripe Discussion

Yeah, check your JS, verify the token gets submitted, something's definitely going on around that.

Posted in Subscriptions with Stripe Discussion

Are you sure that params[:stripeToken] is set to the value from the JS? Check your params?

Posted in Upgrade FedenaProject to latest Ruby application

I think the easiest way to do this is just to upgrade the Ruby version and see what happens. If they have tests, run the tests to see if they still pass. Other than that, you're probably good.

Posted in GoRails speed

Yes! I'm getting a new camera tomorrow, so this will be something I cover first with that. :D

Posted in Pair Programming on Rails Scopes Discussion

Definitely planning to! I think it helps explain things a lot better with the discussion.

Posted in Multitenancy with the Apartment gem Discussion

It works everywhere. You might need to make sure you have Puma running on the correct IP (I think in this case you'd want 0.0.0.0) and that you're accessing the host with the correct port as well.

Posted in has_one association on polymorphic model

You got it! :) So question for you: what are you trying to accomplish exactly with these queries? It might make sense to structure your data a little bit differently to make this more efficient. Your models sound like they're designed to separate everything, but your queries sound like you want don't actually want things separated.

For example, you're wanting to treat activities on notes and activities on comments the same, but your database is structured such that they're separate. It might make more sense to only have activities on the Note level and then include metadata for the related objects like Comment instead.

Posted in has_one association on polymorphic model

Multiple polymorphic associations can be tough because you can't do direct joins in SQL with polymorphic relationships since you're setting the table name in the column itself.

You'll have to make two separate queries along the lines of this:

@comment_ids = Comment.where(commentable_type: "Note", commentable_id: [1,2,3]).pluck(:id)
@activities = Activity.where(trackable_type: "Comment", trackable_id: @comment_ids)

That will first query for the comment IDs on those notes, then it will load up all the activities for those comments on the notes.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.