RailsApps / rails-stripe-membership-saas

An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.
http://railsapps.github.io/rails-stripe-membership-saas
1.14k stars 232 forks source link

NoMethodError in RegistrationsController#create undefined method `amount' for nil:NilClass #163

Open AfolabiOlaoluwa opened 7 years ago

AfolabiOlaoluwa commented 7 years ago

I have an already existing jobs board application, and I have tried to implement this great work with it such that I can have stripe-membership on my http://localhost:3000/companies.

Note changes:

When I click to SignUp for a plan and it renders a SignUp form, I get the following error:

Couldn't find SubscriptionPlan

Fix - I tried to change my Silver Plan id on my SubscriptionPlan table to "0" and it went through which is wrong but dont know what to do with it.

But new problem now is that, when I try to Sign Up for a Subscription Plan as a Company, it fails and give me the following error:

NoMethodError in RegistrationsController#create undefined method `amount' for nil:NilClass

Yet, a company/user as you have it is created right in in my Company's table.

How do I fix all this? If this can be gemified and it intalls as an engine on any already existing model, it would be nice.

psusmars commented 7 years ago

Going to before your fix, can you provide the full stack trace and any relevant methods that are called? What I'm trying to get at is figuring out if the error you're seeing for "Couldn't find SubscriptionPlan" is in a view, controller or model.

beardedguru commented 7 years ago

I actually created an issue not realizing at first that its the same issue here. I will post what I set:

Hey Guys/Gals, want to thank you for your detailed tutorials. I recently was introduced to Rails from a friend that was trying to get me to build this membership product in rails instead of the current platform I am using.

I've worked on this for the past week and problem after problem trying to get this to go live lol. I managed to overcome all of the issues except I keep getting an error when clicking on the signup link:

2017-01-02T22:09:30.705597+00:00 app[web.1]: I, [2017-01-02T22:09:30.705508 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e] Started GET "/users/sign_up" for 99.231.32.114 at 2017-01-02 22:09:30 +0000
2017-01-02T22:09:30.707104+00:00 app[web.1]: I, [2017-01-02T22:09:30.707047 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e] Processing by RegistrationsController#new as HTML
2017-01-02T22:09:30.711700+00:00 app[web.1]: D, [2017-01-02T22:09:30.711605 #4] DEBUG -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   �[1m�[36mPlan Load (1.2ms)�[0m  �[1m�[34mSELECT  "plans".* FROM "plans" ORDER BY "plans"."id" DESC LIMIT $1�[0m  [["LIMIT", 1]]
2017-01-02T22:09:30.713648+00:00 app[web.1]: I, [2017-01-02T22:09:30.713579 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   Rendering devise/registrations/new.html.erb within layouts/application
2017-01-02T22:09:30.714252+00:00 app[web.1]: I, [2017-01-02T22:09:30.714192 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   Rendered vendor/bundle/ruby/2.2.0/gems/payola-payments-1.5.0/app/views/payola/transactions/_stripe_header.html.erb (0.2ms)
2017-01-02T22:09:30.716584+00:00 app[web.1]: I, [2017-01-02T22:09:30.716300 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   Rendered devise/registrations/new.html.erb within layouts/application (2.6ms)
2017-01-02T22:09:30.716958+00:00 app[web.1]: I, [2017-01-02T22:09:30.716899 #4]  INFO -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e] Completed 500 Internal Server Error in 10ms (ActiveRecord: 1.2ms)
2017-01-02T22:09:30.719108+00:00 app[web.1]: F, [2017-01-02T22:09:30.719020 #4] FATAL -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   
2017-01-02T22:09:30.719207+00:00 app[web.1]: F, [2017-01-02T22:09:30.719151 #4] FATAL -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e] ActionView::Template::Error (undefined method `plan_class' for nil:NilClass):
2017-01-02T22:09:30.719528+00:00 app[web.1]: F, [2017-01-02T22:09:30.719470 #4] FATAL -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]      5:   <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form',
2017-01-02T22:09:30.719530+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]      6:         :class => 'payola-onestep-subscription-form',
2017-01-02T22:09:30.719531+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]      7:         'data-payola-base-path' => payola_path,
2017-01-02T22:09:30.719532+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]      8:         'data-payola-plan-type' => resource.plan.plan_class,
2017-01-02T22:09:30.719533+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]      9:         'data-payola-plan-id' => resource.plan.id}) do |f| %>
2017-01-02T22:09:30.719534+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]     10:     <h3>Sign up</h3>
2017-01-02T22:09:30.719535+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e]     11:     <div>
2017-01-02T22:09:30.719606+00:00 app[web.1]: F, [2017-01-02T22:09:30.719555 #4] FATAL -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e]   
2017-01-02T22:09:30.719685+00:00 app[web.1]: F, [2017-01-02T22:09:30.719636 #4] FATAL -- : [1da9d422-f2b8-4461-9474-10de5b5e1a4e] app/views/devise/registrations/new.html.erb:8:in `_app_views_devise_registrations_new_html_erb__2325709040735767357_70274222505740'
2017-01-02T22:09:30.719686+00:00 app[web.1]: [1da9d422-f2b8-4461-9474-10de5b5e1a4e] app/controllers/registrations_controller.rb:12:in `new'
2017-01-02T22:09:30.724433+00:00 heroku[router]: at=info method=GET path="/users/sign_up" host=guruscriptz.herokuapp.com request_id=1da9d422-f2b8-4461-9474-10de5b5e1a4e fwd="99.231.32.114" dyno=web.1 connect=1ms service=17ms status=500 bytes=1669

No method error:

<% end %>
<div class="authform">
  <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form',
        :class => 'payola-onestep-subscription-form',
        'data-payola-base-path' => payola_path,
        'data-payola-plan-type' => resource.plan.plan_class,
        'data-payola-plan-id' => resource.plan.id}) do |f| %>
    <h3>Sign up</h3>
    <div>
      <br />
      <span id="error_explanation" class="payola-payment-error"></span>

Seems to be an issue with 'data-payola-plan-type' => resource.plan.plan_class

beardedguru commented 7 years ago

So ran this in rails console:

CreatePlanService.new.call

and this fixed my issue @AfolabiOlaoluwa.

AfolabiOlaoluwa commented 7 years ago

@beardedguru can you hint what the fix (CreatePlanService.new.call) tackles or fixed really. Somewhat looks like the hack in Seed.rb file. I will give this a try. But I hope it works well on production environment too. Thanks for the fix.

beardedguru commented 7 years ago

@AfolabiOlaoluwa Actually looks like we may have over looked this in the instructions because I saw this in a stackoverflow post but did a quick search for it and it was written in the article here:

https://github.com/RailsApps/rails-stripe-membership-saas/blob/master/README.textile

image