Activity
Always something like that, cascading into a bug showing up elsewhere. :) Glad you got it fixed!
Oh interesting. In that case, is your stripeToken nil?
First I would check to make sure that the user has a stripe_subscription_id saved in the record. You might be passing a nil in on accident.
That's actually my cat. :) He does some chirp-y sounding meows when he sees things outside like birds or squirrels. I'll have to let him in one of the videos soon.
Posted in PDF Receipts Discussion
I definitely will and thanks for the support! :D
Posted in PDF Receipts Discussion
Yeah! So normally with subscriptions, I listen to the charge.created webhook and save a copy of it to the database as a Charge record. That's like the example I use. The reason for needing the webhook is that subscriptions charge the user monthly and they don't have to initiate anything in your app.
For one-time charges, you can create a Charge object immediately during checkout and use that.
And if you want to store the receipt PDF files instead of generating them dynamically each time, you can save the file it generates to S3 and save it using Shrine or Carrierwave, etc and just link to that file from your view.
Posted in How to build REST APIs?
Ali, great suggestion. I definitely will do that. There are only a handful of important concepts you really need to know, and I agree, I haven't seen many videos that actually cover this from a high level. I'll make sure I get to this soon!
When the user registers, do you want to have them fill out some of the profile information as well? If so, then I would recommend updating the Devise form to be a nested form. That way you create both together at once using
accepts_nested_attributes_for
.When Devise creates a user, it does actually sign them in as soon as they're persisted to the database (it would be weird if you registered and then had to login immediately).
Depends on what you want to accomplish really. If you want two things filled out at once, the above solution in #1 is great and pretty painless.
The other option is just to create a blank profile during the registration process if that's what you're looking for. In this case, I would override the Devise controller, copy the create action, and then add in code on the save part to also create and save your profile for the resource.
For example, you could modify the default create action to look like this which would provide an atomic method of creating both the user and the profile:
class Devise::RegistrationsController
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
# We know that the user has been persisted to the database, so now we can create our empty profile
resource.create_profile!
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
end
``
You got it man! 👍 🎉
I made a related episode on this. :) https://gorails.com/episodes/inviting-users-with-devise_invitable
You're welcome Nick! :D
I think the current_period_end timestamp on the Stripe Subscription is what you want there. You could cache this on the user so you don't have to hit their API every time.
You don't necessarily always want to redirect to that same page, this way you can specify it as you want. Of course, you can set it up that way to always set a cookie. Depends on what you're looking to accomplish really.
You could change it to just check to see if there are question marks in the text at all instead.
if line.text.include?("?")
For example, something like this (assuming that's the string):
page.css('span.remain-time').each do |line|
if line.text == "???,??,???"
date = "No date"
else
n = 3
d = line.text[/(\S+\s+){#{n}}/].strip
date = Date.parse(d)
end
puts date
end
Hey Wesley,
Is the line.text
for those actually a string of question marks? I was going to suggest that you could put an if statement in there to check, and then you could have your default "No date" or whatever when it detects that.
Does that help any?
You probably are in a situation where it doesn't matter either way you go. You can just use the ProductUser model and add a role to it if you want to add owners in there. That'll work really nicely. You can then just have:
class User
has_many :product_users
has_many :products, through: :product_users
has_mnay :owned_products, ->{ where(product_users: {role: :owner}) }, through: :product_users, class_name: "Product"
end
This should allow you to have a single table for everything, you won't need the user_id on Product, and the only other thing with this is that when you create a Product you must make sure to create the ProductUser record and set the role to owner
.
That's absolutely on my list. I need to have someone help me with that part as making the videos on their own is time consuming enough. Expect to have transcripts with code snippets sometime in the near future if everything goes well. :)
This looks pretty cool. It might need some updates for newer versions of Rails since it hasn't been updated in a while, but you might check to see if anyone has been maintaining a fork.
Posted in Rails console hacks :)
Hey Sascha, I'd write it like this:
Order.all.each do |tname|
tname.update_attributes(team: User.where(:id => tname.user_id).pluck(:team).shift)
end
The problem is when you use self
it doesn't point to the tname object, causing that issue.