无效的MailChimp列表ID - Rails

时间:2016-08-31 14:37:22

标签: ruby-on-rails templates mailchimp api-key

当我尝试去" localhost:3000 / suscribir"时,我从我的网页上得到了这个错误。我收到了这个错误:

Missing template subscribe/create, application/create with {:locale=>[:es, :en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.

这是我的routes.rb文件......

  post '/suscribir' => 'subscribe#create'
  mount Refinery::Core::Engine, at: Refinery::Core.mounted_path

这是订阅控制器......

class SubscribeController < ApplicationController
  def create
    logger.info "suscripcion #{params.inspect}"
    user = user_params(params)
    MailchimpWrapper.subscribe(user, params[:group_name], params[:group])
    redirect_to '/gracias'
  rescue Mailchimp::Error => e
    logger.error "ERROR mailchimp #{e.message} #{params.inspect}"
  end

  private

  def user_params(params)
    user = {
      email: params[:email].try(:downcase),
      first_name: params[:first_name].try(:titleize),
      last_name: params[:last_name].try(:titleize),
      city: params[:city].try(:titleize),
      phone: params[:phone],
      comment: params[:comment].try(:titleize)
    }
    user
  end
end

您可以查看&#34; redirect_to '/gracias'&#34;

这是gracias.html.erb:

<section class="container thanks-subscribe">
  <span>Gracias por suscribirte!</span>
  <p>Si es la primera vez que te registras a nuestra lista de contactos, revisa tu correo. Te estaremos enviando un correo de confirmación</p>
  <a href="/home"><button>Regresa a la página principal y sigue navegando</button></a>
</section>

没有从mailchimp救援我得到了这个错误..

SyntaxError in SubscribeController#create
C:/Sites/ifurniture/app/controllers/subscribe_controller.rb:22: syntax error, unexpected end-of-input, expecting keyword_end

所以我编辑了它看起来的subscribe_controller.rb:

class SubscribeController < ApplicationController
  def create
    logger.info "suscripcion #{params.inspect}"
    user = user_params(params)
    MailchimpWrapper.subscribe(user, params[:group_name], params[:group])
    redirect_to '/gracias'
  end

  private

  def user_params(params)
    user = {
      email: params[:email].try(:downcase),
      first_name: params[:first_name].try(:titleize),
      last_name: params[:last_name].try(:titleize),
      city: params[:city].try(:titleize),
      phone: params[:phone],
      comment: params[:comment].try(:titleize)
    }
    user
  end
end

并给我这个错误:

Mailchimp::Error in SubscribeController#create
You must provide a MailChimp API key

这是mailchimp_wrapper.rb文件:

module MailchimpWrapper
  def self.subscribe(user, group_name = nil, group = nil)
    mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API_KEY'])
    merge_vars = merge_vars_hash(user, group_name, group)
    mailchimp.lists.subscribe(
      ENV['MAILCHIMP_LIST_ID'],
      { email: user[:email] },
      merge_vars, 
      'html', 
      true, 
      true, 
      false, 
      false
      )
  end

我设置了ENV API_KEY和列表ID,但现在我收到了这个错误..

Mailchimp::ListDoesNotExistError in SubscribeController#create
Invalid MailChimp List ID: 

我检查并且数据是正确的,API和ID列表...在日志中的MailChimp中我看到错误200 List_DoesNotExist

我正在寻求你的帮助,谢谢。

2 个答案:

答案 0 :(得分:2)

请勿从Mailchimp::Error抢救并查看您的实际错误是什么。

在您的救援中,您不会重定向或渲染任何内容,这意味着它会尝试为操作呈现模板,在您的情况下create subscribers。{/ p>

答案 1 :(得分:0)

错误的语法花花公子

  def create
    begin
      logger.info "suscripcion #{params.inspect}"
      user = user_params(params)
      MailchimpWrapper.subscribe(user, params[:group_name], params[:group])
      redirect_to '/gracias'
    rescue Mailchimp::Error => e
      logger.error "ERROR mailchimp #{e.message} #{params.inspect}"
    end
  end