views:

83

answers:

3

I have a simple method in the ApplicationController that, when called, may set a 'flash[:notice]' then redirect to the root_url.

The problem is that even though that method is only called once, the root URL renders that flash[:notice] TWICE.

Here's a the method (which is a before_filter used in other controllers, and is defined in the ApplicationController) :

def authenticate
  if params[:id].try(:size) == 40
    company = Company.find_by_hash_identifier(params[:id])
    if company
      session[:editable_companies] ||= []
      session[:editable_companies] << company.id
      session[:editable_companies].compact!.uniq!
    end
  end
  unless session[:editable_companies].try('&', [company.try(:id), params[:id]])
    flash[:notice]= "You are not permitted to edit this company.<br />Please check the URL from the email we sent you, and try again."
    flash.keep[:notice]
    redirect_to root_url and return
  end
end

In the root_url view, I get two flashes like so:

You are not permitted to edit this company.You are not permitted to edit this company.

A: 

Get rid of the flash.keep(:notice) line.

John Topley
No dice :-/ I've added the original method just to be sure I didn't miss anything in translation.
btelles
Sorry, I gotta vote down since that doesn't solve the problem.
btelles
He was right that you didn't need it.
klochner
Yup, I know I don't need it, but that doesn't solve the problem...kinda sticky...the answer improved the code, but didn't solve the problem. :-)
btelles
+1  A: 

You don't (at least shouldn't) need to call flash.keep(:notice) to store the flash across a redirect. A value in the flash hash only gets auto-deleted on a render.

Kevin
That's what I thought...but removing it doesn't solve the problem either :-/
btelles
A: 

Turns out it was a problem in the view. :-(

I actually had flash[:notice] twice.

btelles
What's up with the down votes? I tried to delete the question, but there were already too many answers...
btelles
Maybe because you are giving downvotes to people who are trying to help you?
Mike Sutton
Wellp, I think I've learned my lesson. Sorry for the downvote Topley!
btelles