Tuesday, January 31, 2012

[Rails] Does Devise make use of a "status" method? Weird bug.

So I've inherited a legacy application and I'm trying to work around the
edges as I put an admin tool interface on top of the existing code base.
I install Devise for user authentication, since I've used it in the
past. I change none of the default code. And yet, on successful sign
in, I get an error:

Render and/or redirect were called multiple times in this action. Please
note that you may only call render OR redirect, and at most once per
action. Also note that neither redirect nor render terminate execution
of the action, so if you want to exit an action after redirecting, you
need to do something like "redirect_to(...) and return".

Here's the thing, look where that error was thrown

vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/rendering.rb:15:in
`render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/instrumentation.rb:40:in
`block (2 levels) in render'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/benchmark.rb:5:in
`block in ms'
/Users/dmorin/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/benchmark.rb:295:in
`realtime'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/benchmark.rb:5:in
`ms'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/instrumentation.rb:40:in
`block in render'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/instrumentation.rb:81:in
`cleanup_view_runtime'
vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/controller_runtime.rb:24:in
`cleanup_view_runtime'
vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.0/lib/action_controller/metal/instrumentation.rb:39:in
`render'
app/controllers/application_controller.rb:9:in `status'


Look at that last line -- the status method of the
application_controller. This is an addition from the legacy code, a
simple monitoring method they installed so that the app responds to a
"/status" call with the text "UP".

I know this to be the problem because if I no longer extend the
ApplicationnController and go straight to ActionController::Base
instead, thus avoiding that status method, then this error goes away.
I'm guessing that the problem goes a little something like this,
"Successful login wants to do a redirect, but then control moves on to
the status method which tries to do a render, and throws that
DoubleRender error." Take out the extra render, and it works.

What I can't figure out for the life of me is how Devise is getting
there in the first place!

The problem is coming from the SessionsController#create method, but
this is just the stock version I've done nothing do it:

# POST /resource/sign_in
def create
resource = warden.authenticate!(:scope => resource_name, :recall =>
"#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end

This is Devise 2.0.0 on a Rails 3.1 app, Ruby 1.9.2p136. I'm just
realizing, as I go googling around, just how new this version of Devise
is. I may need to back out a bit.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate