【发布时间】:2016-07-28 04:55:48
【问题描述】:
已解决:问题来自 Lob 的内部服务器错误。
我正在浏览以下取自this blog on Lob的示例,代码可以在on Github here找到
克隆 repo 后,我 bundle installed gems,启动服务器,然后前往 localhost:3000/postcards。在消息字段中输入一条短消息后,我被重定向到一个错误页面,其中 undefined method `first' for 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
从教程博客看来,这个错误不应该发生。这是什么错误,为什么会在我的环境中发生?
【问题讨论】:
-
请查看(或在问题中发布)来自
development.log的stack trace。在那里你会找到错误的确切位置。 -
另外,如果您查看底部的博客页面评论,您并不是唯一收到此错误的人。看来这是 lob gem 中的错误。完整的堆栈跟踪在这里可能仍然有帮助。
-
@BoraMa 更详细地查看错误消息/日志后,它似乎是 Lob 服务器上的 500 错误。不过感谢您介绍堆栈跟踪,我今天学到了一些新东西。
标签: ruby-on-rails