The user plan and credit card are failing to update when I submit the changes to the form. Its crashing with a 500 error.
Btw, I'm using SubscriptionPlan instead of Plan, to avoid namespace issues on my platform
registrations_controller.rb
def user_change_plan
plan = SubscriptionPlan.find_by!(id: params[:user][:subscription_plan_id].to_i)
unless plan == current_user.subscription_plan
role = User.roles[subscription_plan.stripe_id]
if current_user.update_attributes!(subscription_plan: plan, role: role)
subscription = Payola::Subscription.find_by!(owner_id: current_user.id)
Payola::ChangeSubscriptionPlan.call(subscription, plan)
redirect_to edit_user_registration_path, :notice => "Plan changed."
else
flash[:alert] = 'Unable to change plan.'
build_resource
render :edit
end
end
end
devise_scope :user do
put 'user_change_plan', :to => 'users/registrations#user_change_plan'
authenticated do
root to: 'user_dashboard#index', as: 'authenticated_user_root'
end
unauthenticated do
root to: 'home#index', as: 'unauthenticated_user_root'
end
end
Stack trace
Started PUT "/user_change_plan" for 127.0.0.1 at 2018-11-24 13:01:58 -0500
Processing by Users::RegistrationsController#user_change_plan as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"UTVhe2CIwzvpppGt+QS3K9Qh+OwGbYzlXVkHL5Yn8Pvd6cZ2VhtWV09Rfk3T4bCLRWl1CvEnvImwiMSoNHUnfw==", "user"=>{"subscription_plan_id"=>"4"}, "commit"=>"Change Plan"}
SubscriptionPlan Load (0.0ms) SELECT "subscription_plans".* FROM "subscription_plans" WHERE "subscription_plans"."id" = $1 LIMIT $2 [["id", 4], ["LIMIT", 1]]
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
SubscriptionPlan Load (1.0ms) SELECT "subscription_plans".* FROM "subscription_plans" WHERE "subscription_plans"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
(0.0ms) BEGIN
SubscriptionPlan Exists (1.0ms) SELECT 1 AS one FROM "subscription_plans" WHERE "subscription_plans"."stripe_id" = $1 AND "subscription_plans"."id" != $2 LIMIT $3 [["stripe_id", "silver"], ["id", 4], ["LIMIT", 1]]
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 AND "users"."id" != $2 LIMIT $3 [["email", "cooler@hotmail.com"], ["id", 2], ["LIMIT", 1]]
User Exists (0.0ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = $1 AND "users"."id" != $2 LIMIT $3 [["username", "cooler"], ["id", 2], ["LIMIT", 1]]
(0.0ms) ROLLBACK
Completed 422 Unprocessable Entity in 872ms (ActiveRecord: 4.0ms)
ActiveRecord::RecordInvalid (Validation failed: Password can't be blank, Password is too weak):
app/controllers/users/registrations_controller.rb:44:in `user_change_plan'
Attempting to change only the subscription plan fails also.
The user plan and credit card are failing to update when I submit the changes to the form. Its crashing with a 500 error. Btw, I'm using SubscriptionPlan instead of Plan, to avoid namespace issues on my platform
registrations_controller.rb
users\registrations\edit.html.erb
routes.rb
Stack trace
Attempting to change only the subscription plan fails also.