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

uninitialized constant Stripe #56

Closed pavankat closed 11 years ago

pavankat commented 11 years ago

I'm at the "Migration for the User Model" part of the tutorial. Any ideas why I get this error?

my code is here: https://github.com/pavankat/rails-stripe-membership-saas

When I did

$ rails generate migration AddStripeToUsers customer_id:string last_4_digits:string

I get:

#( 02/02/13@ 6:34PM )( admin@Administrators-MacBook-Pro ):~/desktop/rails-stripe-membership-saas@master✔
   rails generate migration AddStripeToUsers customer_id:string last_4_digits:string
/Users/admin/Desktop/rails-stripe-membership-saas/config/initializers/stripe.rb:1:in `<top (required)>': uninitialized constant Stripe (NameError)
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:587:in `block in <class:Engine>'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/admin/Desktop/rails-stripe-membership-saas/config/environment.rb:5:in `<top (required)>'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/commands.rb:25:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

When I do

rake db:migrate

I get:

#( 02/02/13@ 6:45PM )( admin@Administrators-MacBook-Pro ):~/desktop/rails-stripe-membership-saas@master✔
   rake db:migrate
rake aborted!
uninitialized constant Stripe
/Users/admin/Desktop/rails-stripe-membership-saas/config/initializers/stripe.rb:1:in `<top (required)>'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/engine.rb:587:in `block in <class:Engine>'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/admin/Desktop/rails-stripe-membership-saas/config/environment.rb:5:in `<top (required)>'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/Users/admin/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
DanielKehoe commented 11 years ago

My guess is you overlooked updating the Gemfile and didn't add

gem "stripe"
gem "stripe_event"

If not that, maybe you didn't run bundle install.

pavankat commented 11 years ago

Thanks Dan! It worked. I appreciate you replying to such a beginner mistake.

jerryasmith commented 11 years ago

I'm getting this same error - I just added stripe.rb:

Stripe.api_key = ENV["STRIPE_API_KEY"]
STRIPE_PUBLIC_KEY = ENV["STRIPE_PUBLIC_KEY"]

and when I try to restart the server I get this error:

Jerrys-MacBook-Pro:rails-stripe-membership-saas jerryasmith$ rails server
/usr/local/rvm/gems/ruby-1.9.3-p448@global/gems/bundler-1.3.5/lib/bundler.rb:284: warning: Insecure world     writable dir /usr/local in PATH, mode 040777
/usr/local/rvm/gems/ruby-1.9.3-p448@global/gems/bundler-1.3.5/lib/bundler.rb:284: warning: Insecure world     writable dir /usr/local in PATH, mode 040777
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/jerryasmith/projects/rails-stripe-membership-saas/config/initializers/stripe.rb:1:in `<top (required)>':     uninitialized constant Stripe (NameError)
    from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:587:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:587:in `block in <class:Engine>'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/jerryasmith/projects/rails-stripe-membership-saas/config/environment.rb:5:in `<top (required)>'
from /Users/jerryasmith/projects/rails-stripe-membership-saas/config.ru:3:in `block in <main>'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/jerryasmith/projects/rails-stripe-membership-saas/config.ru:in `new'
from /Users/jerryasmith/projects/rails-stripe-membership-saas/config.ru:in `<main>'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/server.rb:46:in `app'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/server.rb:70:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:55:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:50:in `tap'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

When I delete stripe.rb, the server starts up properly. I checked my Gemfile which includes

gem "stripe"
gem "stripe_event"

and ran bundle install, but still same error.

DanielKehoe commented 11 years ago

Have you set the Stripe keys in config/application.yml or as Unix env variables? What happens when you run rake spec?

jerryasmith commented 11 years ago

Thanks for your reply - the Stripe keys in config/application.yml have been set (xx as placeholder for my real key):

STRIPE_API_KEY: sk_test_xxxxxxxxxxxxxxxxxx
STRIPE_PUBLIC_KEY: pk_test_xxxxxxxxxxxxxxxxxxxx

Here's what I get with rake spec:

Jerrys-MacBook-Pro:rails-stripe-membership-saas jerryasmith$ rake spec
/usr/local/rvm/gems/ruby-1.9.3-p448@global/gems/bundler-1.3.5/lib/bundler.rb:284: warning: Insecure world     writable dir /usr/local in PATH, mode 040777
rake aborted!
uninitialized constant Stripe
/Users/jerryasmith/projects/rails-stripe-membership-saas/config/initializers/stripe.rb:1:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:588:in `block (2 levels) in     <class:Engine>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:587:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/engine.rb:587:in `block in <class:Engine>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/jerryasmith/projects/rails-stripe-membership-saas/config/environment.rb:5:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/application.rb:297:in `block (2 levels) in     initialize_tasks'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => spec => test:prepare => db:test:prepare => db:abort_if_pending_migrations => environment
(See full trace by running task with --trace)
DanielKehoe commented 11 years ago

Really it looks like you don't have the stripe gem. Check it is loaded in your environment with gem list.

jerryasmith commented 11 years ago

Yeah, I'm not sure what the issue could be - they're both loaded when I run gem list. Is there a specific version number?

*** LOCAL GEMS ***

actionmailer (4.0.0, 3.2.12)
actionpack (4.0.0, 3.2.12)
activemodel (4.0.0, 3.2.12)
activerecord (4.0.0, 3.2.12)
activerecord-deprecated_finders (1.0.3)
activeresource (3.2.12)
activesupport (4.0.0, 3.2.12)
addressable (2.3.5)
archive-tar-minitar (0.5.2)
arel (4.0.0, 3.0.2)
atomic (1.1.10)
bcrypt-ruby (3.1.1)
better_errors (0.9.0)
bigdecimal (1.1.0)
binding_of_caller (0.7.2)
bootstrap-sass (2.3.2.1)
builder (3.1.4, 3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
cancan (1.6.10)
capybara (2.1.0)
coderay (1.0.9)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
columnize (0.3.6)
cucumber (1.3.5)
cucumber-rails (1.3.1)
database_cleaner (1.0.1)
debug_inspector (0.0.2)
debugger-ruby_core_source (1.2.3)
devise (3.0.0)
diff-lcs (1.2.4)
email_spec (1.5.0)
erubis (2.7.0)
execjs (1.4.0)
factory_girl (4.2.0)
factory_girl_rails (4.2.1)
figaro (0.7.0)
gherkin (2.12.0)
hike (1.2.3)
i18n (0.6.4)
io-console (0.3)
journey (1.0.4)
jquery-rails (3.0.4)
json (1.8.0, 1.5.5)
launchy (2.3.0)
mail (2.5.4, 2.4.4)
mime-types (1.23)
mini_portile (0.5.1)
minitest (4.7.5, 2.5.1)
multi_json (1.7.7)
multi_test (0.0.2)
nokogiri (1.6.0)
orm_adapter (0.4.0)
polyglot (0.3.3)
quiet_assets (1.0.2)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (4.0.0, 3.2.12)
railties (4.0.0, 3.2.12)
rake (10.1.0, 0.9.2.2)
rb-readline (0.5.0)
rdoc (3.12.2, 3.9.5)
rest-client (1.6.7)
rolify (3.2.0)
rspec-core (2.14.4)
rspec-expectations (2.14.0)
rspec-mocks (2.14.1)
rspec-rails (2.14.0)
ruby-debug-base19 (0.11.25)
ruby-debug-base19x (0.11.30.pre12)
ruby-debug19 (0.11.6)
ruby_core_source (0.1.5)
rubygems-bundler (1.2.2)
rvm (1.11.3.8)
sass (3.2.9)
sass-rails (3.2.6)
simple_form (2.1.0)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
sqlite3 (1.3.7)
stripe (1.8.4)
stripe_event (0.6.0)
thor (0.18.1)
thread_safe (0.1.2)
tilt (1.4.1)
treetop (1.4.14)
tzinfo (0.3.37)
uglifier (2.1.2)
warden (1.2.3)
xpath (2.0.0)
DanielKehoe commented 11 years ago

I just tested with Stripe gem version 1.8.4 and it works.

Try cloning the example app from the repo and see what happens when you run it.

jerryasmith commented 11 years ago

I cloned the example app and it works properly - I may just start from scratch and see if I can find the issue.

tmock12 commented 11 years ago

Jerry make sure your Stripe gem isnt in an environment group in the Gemfile. It shouldn't be in the :devlopment or :test group or anything.

dominathan commented 10 years ago

I had the same issues after adding stripe_event... but forgot to restart the web server. Fixed it right up. Hope that helps someone.