Payola issue: undefined method `amount' for nil:NilClass


I'm just learning how to use Payola to create Subscriptions for my RoR 5.1.5 test app. I'm following along with the instructions on the wiki.

I've set up the sample form taken from the example on the Wiki and dropped it right into app/views/subscriptions/new.html.erb. When I enter the credit card, email, expiration date and click Submit, I get this Rails error: undefined method `amount' for nil:NilClass

I've created the SubscriptionPlan in the rails console and confirmed it exists. I've confirmed that the new Plan shows up in my Stripe dashboard after creating it in the console.

I'm sure I've overlooked something, and hoping someone has experienced this same issue and can point me in the right direction. It feels like I am not specifying the plan anywhere. I'm not sure how I should do that.

Thanks for your help.

Code is here. app/models/subscription_plan.rb

class SubscriptionPlan < ActiveRecord::Base include Payola::Plan end


class SubscriptionsController < ApplicationController # bring in the `render_payola_status` helper. include Payola::StatusBehavior def new @plan = SubscriptionPlan.first end def create # do any required setup here, including finding or creating the owner object owner = current_user # this is just an example for Devise # set your plan in the params hash params[:plan] = SubscriptionPlan.find_by(id: params[:plan_id]) # call Payola::CreateSubscription subscription = Payola::CreateSubscription.call(params, owner) # Render the status json that Payola's javascript expects render_payola_status(subscription) end end


<!-- this header can go in <head> or at the bottom of <body> --> <%= render 'payola/transactions/stripe_header' %> <%= form_tag('/subscriptions', class: 'payola-onestep-subscription-form', 'data-payola-base-path' => '/payola', 'data-payola-plan-type' => @plan.plan_class, 'data-payola-plan-id' => @plan.id ) do |f| %> <span class="payola-payment-error"></span> Email:<br> <input type="email" name="stripeEmail" data-payola="email"></input><br> Card Number<br> <input type="text" data-stripe="number"></input><br> Exp Month<br> <input type="text" data-stripe="exp_month"></input><br> Exp Year<br> <input type="text" data-stripe="exp_year"></input><br> CVC<br> <input type="text" data-stripe="cvc"></input><br> <input type="submit"></input> <% end %>


Rails.application.routes.draw do devise_for :users root to: "pages#index" resources :subscriptions get 'pages/index' get 'pages/donate' mount Payola::Engine => '/payola', as: :payola # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end


In your create action, you mention the SubscriptionPlan's id like so

# set your plan in the params hash params[:plan] = SubscriptionPlan.find_by(id: params[:plan_id])

From your form in the view, I cannot see that you will submit a param called :plan_id. Perhaps post your params from the log file, to make sure the plan's id is there. Otherwise you have to tweak the form to include the plan's id. The plan will be present in the form as @plan, so you could include a hidden field:

<%= hidden_field_tag(:plan_id, @plan.id) %>

Then the plan should be found. Your NoMethodError for nil with the method amount points to the problem, that the plan that the amount method is sent to, is nil. (At least that's my guess)


  • Sign Up Form Error: undefined method `model_name' for NilClass:Class
  • index method in controller not working for active model serializer
  • Saving Entries to Database Relationship (many-to-many) Table from a Backbone Project
  • SQLite, Ruby on rails. How to get the top voted objects with acts_as_votable gem?
  • Can't save Image to database using CarrierWave Direct
  • Play 2.0.4 file upload. NullPointerException: null
  • Rails XML builder not rendering
  • Slicing an SPA into several components and use AngularJS
  • Application bar icon text length
  • what does prefix @- mean in makefile?
  • Add the parent product name to each cart item names in WooCommerce
  • Django model for a Postgres view
  • Using Laravel 5.4 pusher
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Detecting null parameter in preprocessor macro
  • CERN ROOT exporting data to plain text
  • OSX - always hide certain files
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • msbuild create itemgroup from property group
  • Combining two different ActiveRecord collections into one
  • Eloquent paginate function in Slim 3 project using twig
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • $wpdb not working in file of WordPress plugin
  • Meteor helpers not available in Angular template
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Buffer size for converting unsigned long to string
  • KeystoneJS: Relationships in Admin UI not updating
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can I remove ASP.NET Designer.cs files?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal