我正在使用Heroku Postgres :: Onyx的业余爱好层运行在Heroku上托管的rails 4.0.2应用。我的日志文件中出现了一个奇怪的错误,并且记录无法保存。我无法重新创建错误。
2014-05-23T05:28:33.443728+00:00 app[web.1]: [2014-05-23 05:28:33] ERROR invalid body size.
此错误很奇怪的原因是我的应用中唯一的正文字段是文本字段。
以下是相关架构:
create_table "invitation_templates", force: true do |t|
t.integer "business_id"
t.string "subject"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
这是我的模型(顺便说一下,它不包含任何验证):
class InvitationTemplate < ActiveRecord::Base
belongs_to :business
end
这是完整的控制器:
def create
# @user set by correct_user
# @business set by correct_user
@invite = Invite.new(invite_params)
if @invite.valid?
invtemp = InvitationTemplate.find_or_create_by(business_id: @business.id)
invtemp.subject = @invite.subject
invtemp.body = @invite.message
invtemp.save # <--- This is the only line that I can think of as having thrown the error
if invite_params[:image_file].present?
uploaded_io = invite_params[:image_file]
@invite.image_id = Image.add_or_update( @invite.image_id, uploaded_io, "invites" )
end # if params[:image_file].present?
inviter = ManInvite.new
res = inviter.sendInvitation(@invite, @business)
if res
flash[:notice] = "We sent your message(s). You will recieve an email when a new testimonial has been submitted."
else
flash[:error] = "We saved your message(s). But had a problem sending. Please contact support with this information: #{@invite.status} #{@invite.audit_id}"
end
if params[:send_another]
redirect_to( new_business_invite_path(@business) )
else
redirect_to( business_dashboard_index_path(current_user.businesses.first()) )
end
else
render 'new'
end
端
我并不认为文本字段会引发大小错误。任何关于此错误的原因/来源的想法都将受到赞赏。
答案 0 :(得分:2)
我在尝试做一个简单的get时偶然发现了同样的错误。 您看到的错误消息与您拥有一个名为body的属性(至少基于我的情况)无关。 我的问题与一个糟糕的http get请求有关。 我正在使用Alamofire(iOS库)来发出GET请求并将编码设置为JSON。这导致了一个被rails拒绝的无效请求。
如果查看日志,您可能无法查看日志行,例如
Started POST "/invitations ...
这意味着Rails甚至不会解析请求。
检查您的请求,并确保没有错误。
编辑:
我会更直接:问题与你提出请求的方式有关,而不是你有一个身体属性。
我建议您尝试使用Postman(Chrome扩展程序)对您的通话进行快速测试。我已经起草了quick rails app来试用您的方案。 请查看如何使用邮递员向您的服务器发出请求,如下图所示:postman post request。
另外,我已经在heroku中部署了这个草稿应用程序(浮动沙子-5859是应用程序的名称)
答案 1 :(得分:0)
当HTTP POST的标头中的Content-length值出错时,我遇到了类似的错误。 (我将一个Arduino兼容设备发布到rails 4.1 webserver上)
显然旧版本的Firefox存在此问题,因此浏览器可能存在问题。 https://bugzilla.mozilla.org/show_bug.cgi?id=619683
我能够通过修复嵌入式设备程序中的错误来解决错误,但我怀疑你是否能够做同样的事情。