# Flash in a tag module

**URL:** <https://www.ruby-forum.com/t/flash-in-a-tag-module/92769>\
**Category:** Radiant CMS\
**Created:** [April 24, 2007, 1:09am UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769 "2007-04-24T01:09:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 1:09am UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/1 "2007-04-24T01:09:09Z")

</div>

Hi all,

I’m doing some work on an extension, and I’m run into an issue. I’d  
like to pass validation errors on a form back to the tag that draws the  
form. ala:

module FormTags  
include Radiant::Taggable

desc %{  
Displays the form  
}  
tag “form” do |tag|  
form = ‘’  
if flash[:error]  
form \<\< ‘’+flash[:error]+‘’  
end  
…  
end  
end

So, how do I access that? controller.flash doesn’t work, and nor does  
flash (or passing a variable through the class scope).

Thanks for any ideas-

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 4:02am UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/2 "2007-04-24T04:02:20Z")

</div>

Tags exist in the Page model (or a subclass) when processing, so they  
really only have access to the model layer. _However_, the Page model  
has available to it the request and response objects. There are other  
ways to tackle the problem, but you could try getting the information  
from the response object. I believe the flash is stored in the session.

if response.session[‘flash’][:error]

# do something

end

Cheers,

Sean

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/3 "2007-04-24T15:30:50Z")

</div>

On Mon, 2007-04-23 at 22:44 -0400, John W. Long wrote:

> No the flash won’t work because sessions are off for the SiteController.

Oh hell that’s right. So I could either go in and enable them (alter  
radiant), or maybe I’ll just hack it instead.

But yeah, knowing that `response` is in the scope should give me a start  
if I do use sessions. Thanks alot Sean, John.

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 4:46am UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/4 "2007-04-24T04:46:22Z")

</div>

Sean C. wrote:

> Tags exist in the Page model (or a subclass) when processing, so they  
> really only have access to the model layer. _However_, the Page model  
> has available to it the request and response objects. There are other  
> ways to tackle the problem, but you could try getting the information  
> from the response object. I believe the flash is stored in the session.
> 
> if response.session[‘flash’][:error]
> 
> # do something
> 
> end

No the flash won’t work because sessions are off for the SiteController.

So there is really not an easy answer.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/5 "2007-04-24T16:51:14Z")

</div>

> Then in the tag:
> 
> request.params[:error]
> 
> Only issue is rails doesn’t put the GET params into the request.params  
> object, it only puts them in the params object, which isn’t accessible  
> from the tag.

Try request.parameters[:error]. params is a shorthand introduced in  
ActionController I believe.

Sean

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 4:53pm UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/6 "2007-04-24T16:53:14Z")

</div>

On Tue, 2007-04-24 at 09:50 -0500, Sean C. wrote:

> ActionController I believe.

That did it! Thanks Sean.

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/7 "2007-04-24T16:47:14Z")

</div>

On Mon, 2007-04-23 at 21:00 -0500, Sean C. wrote:

> Tags exist in the Page model (or a subclass) when processing, so they  
> really only have access to the model layer. _However_, the Page model  
> has available to it the request and response objects. There are other  
> ways to tackle the problem, but you could try getting the information  
> from the response object. I believe the flash is stored in the session.
> 
> if response.session[‘flash’][:error]
> 
> # do something
> 
> end

Ugh, well as was mentioned sessions are off, So I’m instead attempting  
to pass the info back in a get string during a redirect:

redirect\_to “action”=\>“show\_page”, “url”=\>[“about”],  
“controller”=\>“site”, “error” =\> error

Then in the tag:

request.params[:error]

Only issue is rails doesn’t put the GET params into the request.params  
object, it only puts them in the params object, which isn’t accessible  
from the tag.

Any ideas on that?

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 24, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/flash-in-a-tag-module/92769/8 "2007-04-24T17:18:20Z")

</div>

What if you set a local variable in the Page model? You could use an  
attr\_accessor method called Page#flash.

Or, you could use a cattr\_accessor and define some flash methods like  
this:

class Page \< …  
cattr\_accessor :flash

def self.flash=(message)  
@@flash = {}  
@@flash[:message] = message  
end

def self.flash(key)  
@@flash.delete(key)  
end  
end

Obviously, that logic isn’t the greatest, and I haven’t tested this.  
If it works though please let us know.

On Apr 24, 2007, at 8:30 AM, Matthew B. wrote:

> > > from the response object. I believe the flash is stored in the  
> > > Oh hell that’s right. So I could either go in and enable them (alter
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

* * *

Ryan H.  
Art of Mission, Inc.  
3720 Gattis School Rd #800 PMB 245  
Round Rock, TX 78664

800-722-1492 (phone)

[www.artofmission.com](http://www.artofmission.com)  
removed\_email\_address@domain.invalid
