Skip to content
This repository has been archived by the owner on Oct 16, 2018. It is now read-only.

Configure redirect_path after subscribing

Nate Welling edited this page Aug 9, 2017 · 1 revision

1. First you need to define the path in your <plan_class> model

# app/models/<plan_class>.rb

def redirect_path(subscription)
  # you can return any path here, possibly referencing the given subscription
  # config path in routes.rb, example: get "thanks", to: "<plan_class>#thanks", as: :thanks
  "/thanks"
end

2. Then in the controller, you can configure the redirect paths

# app/controllers/<plan_class>_controller.rb

def thanks
  flash.now[:success] = "<plan_class> signup successful."

  if current_member.subscriptions.active.any?
    @subscription = current_member.subscriptions.active.first
      if (@subscription.cancel_at_period_end? || @subscription.canceled_at?)
        flash[:error] = "<plan_class> has been canceled."
        redirect_to root_path
      end
  else
    flash[:error] = "You do not have access."
    redirect_back(fallback_location: (request.referer || root_path))
  end
end