Rails:nil:NilClass 的未定义方法 'first'



已解决:问题来自Lob的内部服务器错误。

我正在浏览以下示例,这些示例取自 Lob 上的此博客,代码可以在 Github 上找到

这里

克隆存储库后,我bundle installed宝石,启动服务器,然后前往localhost:3000/postcards。在消息字段中输入一条短消息后,我被重定向到一个错误页面,其中未定义的方法"first"表示 nil:NilClass 错误。

错误似乎出在控制器中

class PostcardsController < ApplicationController
  LOB = Lob.load(api_key: "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc")
  def index
  end
  def create
    template_file = ERB.new(File.open(File.join(Rails.root, 'app', 'views', 'postcards', 'postcard_front.html.erb')).read)
    custom_html = template_file.result(binding)
    @results = LOB.postcards.create(
      name: "Demo Postcard",
      to: {
        name: params[:postcards][:to_name],
        address_line1: params[:postcards][:to_address_line1],
        city: params[:postcards][:to_city],
        state: params[:postcards][:to_state],
        zip: params[:postcards][:to_zip],
        country: "US",
      },
      from: {
        name: params[:postcards][:from_name],
        address_line1: params[:postcards][:from_address_line1],
        city: params[:postcards][:from_city],
        state: params[:postcards][:from_state],
        zip: params[:postcards][:from_zip],
        country: "US",
      },
      front: custom_html,
      message: params[:postcards][:message],
      full_bleed: 1
    )
  end
end

从教程博客来看,此错误似乎不应该发生。此错误是什么,为什么它发生在我的环境中?

在 GitHUb 上有一个悬而未决的问题。我收到同样的错误。2016/7/27

最新更新