Activity
This looks like a fun project! If you've already got elasticsearch going, it'll do really well to handle the search queries (plus it should handle the ordering from closes to furthest as well). Curious to hear how it goes man!
I would probably use the Geocoder gem for this. You can back it with interchangeable APIs and cache results in Redis which is really handy.
Have you considered using the geosearch that's built into ElasticSearch? You can pass it in either a bounding box (like the coordinates of a Google Map embedded on the page like Yelp does if you drag the map), or you can search within a radius, so you can easily find things by km or miles away.
What's your UI going to look like for the interactions?
Templates are a definitely interesting topic. I spent some time making templates in the past and I believe I ended up trying a couple different things. One approach I had a templates table, but it felt like there was a lot of duplication going on (two tables, same columns for example). The other was to mark records as templates and we'd just copy a few fields over to the new record. That ended up working better for what we were doing because it was pretty simple.
I personally like just operating off an existing record because you can just say "Okay, let's dup this, including it's children, but only keep these certain fields, strip out these others" and you don't have to deal with creating multiple tables or anything.
If you go that approach, you can use the .dup
method on the instance, so you'd load up the original and then call .dup
on it which should generate a copy in memory without an ID attached. You might also need to loop through associated records and dup those as well for the new model. Then you can clean any of the fields you want by setting them to nil or whatever.
The other approach for this same thing is to take the attributes from the original, use except
on the hash to strip out those fields, and then create a new record like you normally would in the controller. Either way is effectively the same, this one might be a lot more familiar to most people. .dup
wins if you don't need to strip out any fields though because everything's already set automatically.
Posted in Memoization Discussion
Yes, great point! Thanks for mentioning that.
Posted in Subscriptions with Stripe Discussion
Double check that the authenticity token is being submitted in the params. Your screenshot looks like it isn't being included. It might be not making a POST request and just doing a normal GET, which isn't what you want.
Posted in Subscriptions with Stripe Discussion
You might double check that that file is getting required in your application.js. Sometimes that can be all that's missing. If it is, then add some print statements to see if your code is actually running, might be just something simple there.
Posted in About In-App Navbar Notifications
Bunch of different ways you could do this, but in most cases, you're going to want to base this off two things
- the class name of the notifiable (ForumPost, User, ForumThread, etc)
- the action that happened (commented, subscribed, asked, etc)
Most of the time each time one of these two things change, you'll want to render a different snippet of JSON.
The two main approaches I'd suggest are as follows:
1 -Use a case statement to break down the notifiable to the class and action, then return the proper url for it. You could define this stuff in helper methods.
case notification.notifiable
when ForumThread
case notification.action
when "created"
forum_thread_path(notification.notifiable)
end
when User
case notification.action
when "subscribed"
admin_user_path(notification.notifiable)
end
end
This is pretty straightforward and really easy to customize the URLs. You can just adapt things easily, refactor this to methods with case statements if it gets too long and unwieldy, etc.
Of course, this breaks down when you need to start customizing the JSON more than just different URLs, so that's why option #2 might make more sense.
2 - Another way to do this is to render partials dynamically, but you have to make sure if you introduce a new notification type, you must make sure you create a template for it. This is what I generally do so that everything is nicely organized and easily customizable.
json.partial! "notifications/#{notification.notifiable.model_name.route_key}/#{notification.action}", notification: notification
For example, this would take a notification that's notifiable is a ForumThread
and the action created
and render the app/views/notifications/forum_threads/created.json.jbuilder
template. In there you could define your details, like the different url, etc.
In most applications, notifications often end up needing more complex metadata for each one, so this is a case where it makes more sense to define each one's JSON individually. You can include different data structures where as in the first approach, it's much harder to.
It all really depends what you want to do, but I'd suggest starting with the first one, and refactoring into the second one as things progress if necessary.
Posted in Memoization Discussion
I hadn't seen this before, quite an interesting approach. I like the intentions / goals a lot and a good discussion about it. There's a certain elegance to it that feels very clean.
That said, I'm not sure memoization is really necessary for any of this. It might be useful in post_params, but it's one of those cases like name where it's ultra fast to run and only usually gets access once, so unlikely to provide any speed benefits to memoize.
For example, you can just use before_actions to accomplish the same result: https://gist.github.com/exc...
The benefit of instance variables is that it provides you a way at a glance to determine which variables you have access to in your views, plus they're automatically available as well without having to expose helper_methods.
And like the discussion mentioned, for the index methods they tend to have scopes applied often, so I usually find them useful to always be written in the method so you can easily find it, rather than having to look at helper methods or before_actions for that. It makes more sense for member actions where you've always got to set @post for example and it's kind of assumed that it'll always be the same.
What do you think?
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.
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.
Thanks for much for that Zachary! :)
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.