views:

273

answers:

1

In a project which uses restful_authentication with acts_as_state_machine and email activation, I get a double render error whenever a user does the activation action from the email link.

I'm using the default

def activate
   self.current_user = params[:activation_code].blank? ? false : User.find_by_activation_code(params[:activation_code])
   if logged_in? && !current_user.active?
   current_user.activate!
   flash[:notice] = "Signup complete!"
   end
   redirect_back_or_default('/')
end

to activate, and the default

def redirect_back_or_default(default)
  redirect_to(session[:return_to] || default)
  session[:return_to] = nil
end

to redirect. The redirect method works in every other case it's called in the same way.

The double render error occurs at the render of the page main_page/home that is routed as "/".

What should I be looking for?

+1  A: 

Acts As State Machine will sometimes have some odd behavior where the saved record written to the database will be out of sync with the object in memory. I bet you have a situation where the ruby object corresponding to the newly activated user is not being updated even though the field in the db is being set (of vice versa).

I'd need to see the controller action that actually runs to render the route you have setup to match "/", but I bet you've got subtly inconsistent cases in that action that are being tripped up by this inconsistency in AASM. Try reloading the user object at the start of that controller action to see if the problem goes away. If not begin debugging by making sure that your state changes are actually being saved out to the db.

Greg Borenstein