We've moved discussions to Discord

Question about data on plans

Willard Moore
So I'm looking at how a plan is saved. It looks like the stripe id is saved with the features in the details, and that there is still a features column on the db. It doesn't look intentional, but I'm not sure what way you're going to change it to in the future. 
Also, finding that the plans are sorted based on which ever one was updated last. Might be good to have a column to specify a sort order.

Plan Load (2.4ms)  SELECT "plans".* FROM "plans" WHERE "plans"."interval" = $1  [["interval", "month"]]
=> [#<Plan:0x00007fc15a38b350
  id: 1,
  name: "Bells",
  amount: 0,
  interval: "month",
  details: {"features"=>["Yes, It's actually free", "These are just for an example"], "stripe_id"=>"free", "braintree_id"=>""},
  created_at: Thu, 31 Oct 2019 03:20:13 UTC +00:00,
  updated_at: Thu, 31 Oct 2019 03:34:48 UTC +00:00,
  features: nil>,
 #<Plan:0x00007fc15a38b288
  id: 3,
  name: "Whistles",
  amount: 0,
  interval: "month",
  details: {"features"=>["Example plan", "Also Free "], "stripe_id"=>"free2", "braintree_id"=>""},
  created_at: Thu, 31 Oct 2019 03:32:12 UTC +00:00,
  updated_at: Thu, 31 Oct 2019 03:40:50 UTC +00:00,
  features: nil>,
 #<Plan:0x00007fc15a38b1c0
  id: 4,
  name: "Bells & Whistles",
  amount: 0,
  interval: "month",
  details: {"features"=>["Why not have it all! ", "Subscription not actually required."], "stripe_id"=>"free3", "braintree_id"=>""},
  created_at: Thu, 31 Oct 2019 03:33:06 UTC +00:00,
  updated_at: Thu, 31 Oct 2019 03:41:25 UTC +00:00,
  features: nil>]
Willard Moore
Also,  Chris Oliver . You're awesome, thanks!
Chris Oliver
Willard Moore Yeah, the stripe and braintree IDs are stored in the json column. It just makes it easy for us to add more things later without migrations. You can still query against it if you want to find a plan by Stripe ID.

Definitely good point on the sort order. Those should probably sort by amount.
Chris Oliver
I misspoke. Plans already sort by amount. Your amounts are both 0, so there's no guarantee of sort order for plans with equal amounts.
Willard Moore
That makes sense. Looks like it must go by amount first and then by updated_at as a 2ndary sort option based on my experience then. 

Oh, another thing I found to be weird is that an admin by default can't access content because he doesn't have a subscription. 
Also the admin edit subscription page for me was erroring out(500 I think). I haven't looked into it much yet. 
Chris Oliver
I like the idea of adding a free subscription to the admin users created in the Jumpstart admin by default. 👍
Willard Moore
I think I would just add logic permitting admin users as well as subscribed users. Also, I noticed that giving someone admin access requires that an admin has a user's password by default. Would be nice to not need that in order to give admin access from the UI(admin panel). 
Chris Oliver
I pretty regularly add free subscriptions for friends to my apps, so I'm going to add a hidden Free plan that's used for admins and other users, and that way we can keep it all consistent.

I'll take a look at marking another user as an admin and see about fixing that.
Chris Oliver
You can just remove the `owner_id` from the subscription_dashboard.rb file. That shouldn't be there. I'll have that updated in the sca branch.
Willard Moore
I like that there would be a hidden free plan. The template doesn't have hidden plans by default. That would be nice too. being able to toggle hidden or not, and keep it available to the admin anyway. I like it. Good experience and more flexible than requiring them to be an admin in order to be free. 😀  
Jason Ackerman
Willard Moore   Chris Oliver  Did you end up adding the free hidden plan? I see the free plan, but it is showing up on my pricing page and I don't see a way to toggle it as hidden. Thanks!
Chris Oliver
Try this

1. Add hidden to the store_accessor
  store_accessor :details, :features, :stripe_id, :braintree_id, :jumpstart_id, :hidden

2. Add a scope:
  scope :without_hidden, -> { where.not("details @> ?", {hidden: true}.to_json) }

3. Then add the scope to your pricing page.

Since it's an attribute this way, you can add it to the Administrate dashboard to toggle there as well. Seems easy enough to add to the template so I might just do that. 👍
Jason Ackerman
Success, thanks  Chris Oliver !

This was already in Plan.rb and included in the monthly and yearly scopes, but setting the jumpstart_id to :free was not excluding it from the Pricing page:
scope :without_free, -> { where.not(details: {jumpstart_id: :free}) }

The solution you provided above worked, thanks again!
Jason Ackerman
The above worked when I set :hidden to true in the Rails console, however, when I add it to my administrate dashboard the field is being set to either "0" or "1", which is not being recognized by the scope. Not a huge deal since I'm fine setting it from the console, but wanted to mention it here Chris Oliver

On the administrate dashboard it is set as:
hidden: Field::Boolean
and appears as a checkbox on the form.
Notifications
You’re not receiving notifications from this thread.