Rich
Rich

Reputation: 122

Heroku Rails Log Error Message on text field: ERROR invalid body size

I'm running a rails 4.0.2 app hosted on Heroku using the hobby tier of Heroku Postgres :: Onyx. I got an odd error in my log file and a record failed to save. I can't recreate the error.

2014-05-23T05:28:33.443728+00:00 app[web.1]: [2014-05-23 05:28:33] ERROR invalid body size.

The reason that this error is odd is that the only body field anywhere in my app is a text field.

Here is the relevant schema:

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

Here is my model (which contains no validations by the way):

class InvitationTemplate < ActiveRecord::Base

  belongs_to :business

end

Here is the complete controller:

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

end

I didn't think that text fields could throw a size error. Any thoughts on the cause/source of this error would be appreciated.

Upvotes: 1

Views: 1453

Answers (2)

rpbaltazar
rpbaltazar

Reputation: 801

I have stumbled against the same error while trying to do a simple get. The error message that you are seeing has nothing to do with the fact that you have an attribute called body (at least based on my case). My problem was related with a bad http get request. I was using Alamofire (iOS library) to make the GET request and setting the encoding as JSON. This was making an invalid request that was being rejected by rails.

If you look at your logs, you'll probably won't see a log line such as Started POST "/invitations ... which means that the request is not even parsed by Rails.

Check how you are making your request and make sure there is not a bug there.

EDIT:

I'll be more direct: The problem is related to the way you are making your request and not with the fact that you have a body attribute.

  1. If you're doing the request via a browser, through clicking a URL check that it is not related with the reported bug on the previous comment.
  2. If you're building the request yourself, by using a third-party library, check that the request is being build properly.

I suggest you to try to Postman (chrome extension) to make a quick test to your call. I've drafted a quick rails app to try out your scenario. Check how you can make a request with postman to your server in the following image: postman post request.

Also, I've deployed this draft app in heroku (floating-sands-5859 is the name of the app)

Upvotes: 2

user3670244
user3670244

Reputation: 1

I got similar errors when the Content-length value in a HTTP POST's header is wrong. (I'm having an Arduino compatible device post to a rails 4.1 webserver)

Apparently an old version of Firefox had a problem with this, so it might be a problem with your browser. https://bugzilla.mozilla.org/show_bug.cgi?id=619683

I was able to fix the error by fixing the bug in my embedded device's program, but I doubt you'll be able to do the same.

Upvotes: 0

Related Questions