uninitialized constant Stripe::Price

Viewed 284

I cannot create a price with stripe.

I've already done

  • add gem stripe (5.17.0)
  • bundle install

[Developing Enviroment]

  • ruby 2.6.3
  • rails '~> 6.0.2', '>= 6.0.2.1'

this is my posts_controller.rb

class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]
  require 'stripe'

・・・

  def new
    @post = Post.new
  end

  def create
    @post = current_user.posts.build(post_params)
    key = current_user.access_code
    Stripe.api_key = key
    product = Stripe::Product.create({
      name: @post.title,
    })
    price = Stripe::Price.create({
      currency: 'jpy',
      product: product.id,
      type: 'one_time',
      unit_amount: @post.price,
    })

this is my gemfile that I bundle install

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
gem 'sqlite3', '~> 1.4'
gem 'puma', '~> 4.1'
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'devise'
gem 'stripe'
gem 'dotenv-rails'
gem 'omniauth-stripe-connect'
gem 'omniauth'
gem 'gon'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Thank you for watching, please help me. I'm struggling with this issue for 3hours.....

0 Answers
Related