rack handler chokes on nil when redirect in filter
Reported by bryan | March 2nd, 2008 @ 05:26 AM
class Foo < Application
def index
redirect 'http://merbivore.com'
end
end
works as expected
class Foo < Application
before :choke
def choke
redirect 'http://merbivore.com'
end
end
Read error: #<NoMethodError: undefined method `each' for nil:NilClass>
/usr/local/lib/ruby/gems/1.8/gems/merb-core-0.9.0/lib/merb-core/rack/handler/mongrel.rb:82:in `process'
Comments and changes to this ticket
-
bryan March 3rd, 2008 @ 03:18 AM
after reading more about rack and going through the filters code in abstract_controller, the filter, running redirect provides a body (necessary for rack) but it doesn't get passed to the action called. Updating the example above, you can eliminate the error by passing a string in the called action.
@@ Ruby
class Foo < Application
before :choke
def choke
redirect 'http://merbivore.com'
end
def index
""
end
end
@@
As I am still getting familiar with the architecture, I'm not sure where to apply a patch.
-
Yehuda Katz (wycats) March 4th, 2008 @ 01:22 AM
- → State changed from new to invalid
You can't just return a string (what redirect does) from a before filter. You need to throw halt:
before :choke def choke throw :halt, redirect("http://merbivore.com") end -
bryan March 4th, 2008 @ 01:51 PM
The patch I had written did just that, in the redirect method. But now that I see your comment, it makes sense; I just wasn't grasping the big picture on how Merb thinks. Thanks!
-
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 »
