Mongrel Rack handler fails when returning empty string to file upload
Reported by Eliot Shepard | June 26th, 2008 @ 06:45 PM | in 0.9.4
What is the problem?
Running under stock Mongrel/Rack, dev mode.
Resource User, has_one :avatar
views/users/edit.html.rb:
<% form_tag :action => url(:user, @user), :method => :put, :multipart => true do %>
<%= file_field :name => "avatar[uploaded_data]" %>
<%= submit_button "Save avatar" %>
<% end %>
controllers/users.rb:
def update
end
Result:
~ Started request handling: Thu Jun 26 11:28:12 -0400 2008
~ Routed to: {:format=>nil, :action=>"update", :controller=>"users", :id=>"2"}
~ Params: {"format"=>nil, "action"=>"update", "_method"=>"put", "id"=>"2", "controller"=>"users", "avatar"=>{"uploaded_data"=>{"content_type"=>"image/jpeg", "size"=>447751, "tempfile"=>#<File:/var/folders/bc/bcD7GQarGIac2VmV-+CxQ++++TI/-Tmp-/Merb.7572.3>, "filename"=>"06_6.jpg"}}}
~ User Load (0.000482) SELECT * FROM `users` WHERE (`users`.`id` = 2)
~ {:after_filters_time=>1.2e-05, :before_filters_time=>0.001111, :action_time=>0.002216, :dispatch_time=>0.191113}
~
Thu Jun 26 11:28:12 -0400 2008: Read error: #<NoMethodError: undefined method `each' for nil:NilClass>
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/handler/mongrel.rb:85:in `process'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/rack/adapter/mongrel.rb:22:in `start'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core/server.rb:53:in `start'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/lib/merb-core.rb:87:in `start'
/Library/Ruby/Gems/1.8/gems/merb-core-0.9.4/bin/merb:12
/usr/bin/merb:19:in `load'
/usr/bin/merb:19
What is the cause?
Rack::Handler::Mongrel#process does not handle a nil body for multipart/form-data (or the body is falsely reported to be nil by the app).
Comments and changes to this ticket
-

Ben Alpert (spicyj) June 27th, 2008 @ 11:21 PM
It looks like this is a problem with Rack, not Merb. Try posting on the rack-devel Google Group.
-
Michael Klishin (antares) June 28th, 2008 @ 09:50 PM
- → Milestone changed from to 0.9.4
- → State changed from new to open
That handler is provided by Merb so it is a Merb problem. What your upload action does after file is processed? i.e. why response body is nil? is it you app specific?
-

-

beawesomeinstead July 13th, 2008 @ 11:47 AM
# Redirect to the URI stored by the most recent store_location call or to the passed default. def redirect_back_or_default(default = "/") # Couses a bug http://merb.lighthouseapp.com/pr... redirect session[:return_to] || default session[:return_to] = nil end -
Michael Klishin (antares) July 13th, 2008 @ 12:00 PM
- → Assigned user changed from to Michael Klishin (antares)
- → State changed from open to resolved
Turns out it's not a bug. If you return nil as body, which is last line of your code does by assigning nil, your application does not conform to Rack standards. It's a tricky thing but in all cases where you see it, return an some string from your action and it's gonna be ok.
For instance, you can assign session[:return_to] to local variable, set it to nil then make a redirect that returns You have been redirected string.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
