Closed laurenierullo closed 9 years ago
Could you post your destroy method here?
In users_controller.rb it's:
def destroy authorize! :destroy, @user, :message => 'Not authorized as an administrator.' user = User.find(params[:id]) unless user == current_user user.destroy redirect_to users_path, :notice => "User deleted." else redirect_to users_path, :notice => "Can't delete yourself." end end
change user.destroy
to user.destroy!
If the user can't be deleted it will raise an ActiveRecord::RecordNotDestroyed
and give you a hint at why.
I just checked heroku logs and it says: Stripe Error: No such customer: cus_4sXwe7fEQCawBH; a similar object exists in test mode, but a live mode key was used to make this request.
I didn't realize that users created in test mode could still be listed, but technically not exist once I switched to live. I'm able to delete users that signed up once I switched to live, but none of my testers can access their accounts. Is there a way I can delete them from the command line so they can create accounts again? Or even better, migrate them to become live users?
Check the Heroku docs on how to reset the database.
I just did: heroku pg:reset DATABASE (this deleted everything!) heroku run rake db:migrate heroku run rake db:seed
Now I'm the only user. That was not my intention but I'm really new at this and am learning as I go.
Thank you so much for creating this starter app! I originally found it because I was having trouble connecting stripe with devise. :)
You're welcome. The rails-stripe-membership-saas app is fairly complex so you're doing very well. If you can, you may want to read my book Learn Ruby on Rails or look at the RailsApps tutorials for some of the simpler applications, just to get a little more comfortable.
I will! Thank you! One last thing, I just created another test account, upgraded, and then deleted the account. The upgrade went through in stripe but not the deletion. This would mean a user would still get charged after supposedly deleting their account. Is there a fix for this?
FYI The app I created is www.fitnova.com :)
Take a look at the User model. A cancel_subscription
method is called before the user is destroyed. Not sure why that didn't happen for you.
In user.rb it says: before_destroy :cancel_subscription .... def cancel_subscription unless customer_id.nil? customer = Stripe::Customer.retrieve(customer_id) unless customer.nil? or customer.respond_to?('deleted') subscription = customer.subscriptions.data[0] if subscription.status == 'active' customer.cancel_subscription end end end
In edit.html.erb:
Perminently <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'btn btn-mini' %>
Try debugging it. Put a log message in the cancel_subscription
method.
See the "Troubleshoot" chapter. Or (for free): http://guides.rubyonrails.org/debugging_rails_applications.html#the-logger
Just signed up. Thanks for your help.
There is a new version of this application for Rails 4.2 using the Payola gem.
As an admin I click 'delete user' and I get the green confirmation msg:
"User deleted."
However, the user remains there. What can I do to fix this? Why is it happening?