2016-06-24 3 views
1

Я пытаюсь выполнить Basic Mailing List Setup с помощью Gibbon и Mailchimp.неинициализированная константа Gibbon :: Request (NameError)

I'm постоянно получаю эту ошибку, когда я начинаю мой рельсы сервер rails s

Я даже понижен до версии gem 'gibbon', '~>1.2.0'

, но до сих пор мой журнал выглядит как этот

/Users/dadi/Documents/Vefir/stores/brainstore/config/initializers/gibbon.rb:2:in `<top (required)>': uninitialized constant Gibbon::Request (NameError) 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:651:in `load_config_initializer' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:615:in `block in <class:Engine>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:44:in `tsort_each_child' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `call' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!' 
from /Users/dadi/Documents/Vefir/stores/brainstore/config/environment.rb:5:in `<top (required)>' 
from /Users/dadi/Documents/Vefir/stores/brainstore/config.ru:3:in `block in <main>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize' 
from /Users/dadi/Documents/Vefir/stores/brainstore/config.ru:in `new' 
from /Users/dadi/Documents/Vefir/stores/brainstore/config.ru:in `<main>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>' 
from /Users/dadi/Documents/Vefir/stores/brainstore/bin/rails:9:in `require' 
from /Users/dadi/Documents/Vefir/stores/brainstore/bin/rails:9:in `<top (required)>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' 
from /Users/dadi/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' 
from /Users/dadi/Documents/Vefir/stores/brainstore/bin/spring:13:in `<top (required)>' 
from bin/rails:3:in `load' 
from bin/rails:3:in `<main>' 
[email protected] brainstore (AddingMailChimp) $ 

I» ve по этой ссылке http://cheshireoctopus.github.io/blog/2014/01/23/mailchimp-plus-gibbon-plus-rails-create-a-basic-sign-up-form/

и этот http://aspiringwebdev.com/e-mail-in-rails-with-mailchimp-and-mandrill-a-comprehensive-guide/

и я сделал различные модификации в соответствии с сообщениями stackoverflow, но все еще ничего не работает.

Я не имеют понятия, что происходит здесь, но это было бы очень полезно, если бы кто-то может мне посоветовать ...

это мой конфиг/Инициализаторы/gibbon.rb

require 'gibbon' 
    gibbon = Gibbon::Request.new(api_key: "myAPIkey") 
    Gibbon::API.timeout = 15 
    Gibbon::API.throws_exceptions = false 

emailapi_controller.rb

class EmailapiController < ApplicationController 
    def index 
    end 

    def subscribe 

    @list_id = "myLISTid" 
    gb = Gibbon::API.new 

    gb.lists.subscribe({ 
    :id => @list_id, 
    :email => {:email => params[:email][:address]} 
    }) 

    end 
end 

Gemfile.rb

source 'https://rubygems.org' 



# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.5' 
# Use postgresql as the database for Active Record 
gem 'pg', '~> 0.15' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# See https://github.com/rails/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use Unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

group :development, :test do 
# Call 'byebug' anywhere in the code to stop execution and get a debugger console 
gem 'pry-rails' 
end 

group :development do 
# Access an IRB console on exception pages or by using <%= console %> in views 
gem 'web-console', '~> 2.0' 

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
gem 'spring' 

gem 'dotenv-rails' 

end 

gem 'social-share-button' 
gem 'bootstrap-sass' 
gem 'autoprefixer-rails' 
gem 'carrierwave' 
gem 'mini_magick' 
gem 'puma' 
gem 'devise' 
gem 'country_select' 
gem 'braintree' 
gem 'rails_12factor', group: :production 


gem 'gibbon', '~>1.2.0' 


group :test do 
    gem 'minitest-rails' 
    gem 'factory_girl_rails' 
end 

ответ

4

Если кому-то интересно, мне удалось это исправить, выполнив следующее.

в Gemfile я изменил gem 'Gibbon' на gem 'gibbon', :git => 'https://github.com/amro/gibbon.git'

я изменил emailapi_controller.rb к

class EmailapiController < ApplicationController 
def subscribe 
    @list_id = ENV["MAILCHIMP_LIST_ID"] 
gibbon = Gibbon::Request.new 

gibbon.lists(@list_id).members.create(
    body: { 
    email_address: params[:email][:address], 
    status: "subscribed" 
    } 
) 

respond_to do |format| 
    format.json{render :json => {:message => "You have been Successfully added to the list! :)"}} 
    end 
    end 
end 

Инициализаторы/gibbon.rb должно быть так:

Gibbon::Request.api_key = ENV["MAILCHIMP_API_KEY"] 
Gibbon::Request.timeout = 15 
Gibbon::Request.throws_exceptions = false 

и MAILCHIMP_API_KEY и MAILCHIMP_LIST_ID хранятся в application.yml, созданных камнем figaro

надеюсь, что это поможет, если кто-то споткнется на ту же ошибку.

0

Текущий README для Гиббона относится к Gibbon 2.x. Я предлагаю использовать версию выпуска вместо того, чтобы указывать Gemfile на github. например

gem 'gibbon', '~>2.2.4'