Activity
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.
Posted in Subscriptions with Stripe Discussion
Are you sure that params[:stripeToken] is set to the value from the JS? Check your params?
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
Definitely planning to! I think it helps explain things a lot better with the 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.