Forum: Ruby on Rails Access flash from a model class?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
39045f22049b1db3e3dd08c3bffac17e?d=identicon&s=25 Filip Godsmurf (godsmurf)
on 2006-03-07 19:56
I have a method that returns either a comment stored in the flash (if it
exists) or a new comment. It works when I put it in my application
controller:

  def preform_comment
    if flash[:badcomment].nil?
      comment = Comment.new
      return comment
    else
      return flash[:badcomment]
    end
  end

However it would be cleaner to put this in the Comment model, so I
tried:

  def self.preform
    if flash[:badcomment].nil?
      comment = Comment.new
      return comment
    else
      return flash[:badcomment]
    end
  end

But then I get the error

undefined local variable or method `flash' for Comment:Class

Is there another way to access the flash from the model?
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Mikkel Bruun (Guest)
on 2006-03-07 20:28
(Received via mailing list)
Why woud it be cleaner???

Does your model know about flash?? does your model know http???

Flash is strictly view and not model....

Keep it in the controller

On Tuesday, March 07, 2006, at 7:56 PM, Filip Godsmurf wrote:
>    end
>      return flash[:badcomment]
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


Mikkel Bruun

www.strongside.dk    - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
This topic is locked and can not be replied to.