# How do you get flash to store something other than a string?

**URL:** <https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849>\
**Category:** Rails\
**Created:** [March 13, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849 "2008-03-13T20:08:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 13, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849/1 "2008-03-13T20:08:22Z")

</div>

Hi,

So I’ve built a page controller that lists pages, with a link to edit  
the page.

When you click the edit button, the edit view lists the page title and  
the associated articles with that page, using:

(in the controller)  
@articles\_pages, @articles = paginate(:articles, :conditions=\>  
[‘page\_id = ?’, @page])

Article is a separate model with a belongs\_to :page in its model and a  
foreign key page\_id.

The trouble comes when the user clicks on the Edit Article link. It  
opens up the edit view and displays the article, with the following  
displayed:

# Editing article

\<% form\_tag :action =\> ‘update’, :id =\> @article do %\>  
\<%= render :partial =\> ‘article\_form’ %\>  
\<%= submit\_tag ‘Edit’ %\>  
\<% end %\>

\<%= link\_to ‘Show’, :action =\> ‘show’, :id =\> @article %\> |  
\<%= link\_to ‘Back’, :action =\> ‘edit\_page’, :id=\>@page.id %\>

The last line is the problem. I need some way for the application to  
remember which page is associated with the article and return the user  
to editing the page from the edit article form.

I’m not sure if I should pass a param here or store the id in flash?

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 13, 2008, 9:06pm UTC](https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849/2 "2008-03-13T21:06:42Z")

</div>

Flash is a mechanism for displaying text onto the view. If you want to  
“store” other types of data, you should use either a cookie or the  
session.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 13, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849/3 "2008-03-13T21:45:10Z")

</div>

On 13 Mar 2008, at 20:06, Nathan E. wrote:

> Flash is a mechanism for displaying text onto the view. If you want to  
> “store” other types of data, you should use either a cookie or the  
> session.

Actually the flash isn’t magic at all. It’s just a hash which is  
auomatically emptied at the right time (and it is actually stored in  
the session).  
It’s commonly used for passing strings around, but I don’t see why you  
couldn’t stick in it anything you could stick in the session.

Fred

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 14, 2008, 4:27am UTC](https://www.ruby-forum.com/t/how-do-you-get-flash-to-store-something-other-than-a-string/131849/4 "2008-03-14T04:27:47Z")

</div>

Thanks Fred and Nathan.

I guess perhaps I asked the wrong question–the real question here is  
how do you retrieve the page that is associated with the array of  
articles again when the user is done editing?

I’ve tried this:

I’ve defined a page\_id method in the article model.

def self.page\_id  
Article.page\_id  
end

Then in the edit action in the articles controller,

@page=Page.find(:conditions=\>[‘id = ?’, Article.page\_id])

Then in the edit view:  
\<%= link\_to ‘Back’, :action =\> ‘edit’, :controller=\>‘page’, :id=\>@page  
%\>

I don’t think I’ve done this right. Now I’m getting stack level too  
deep error.

Ron

P.S. Fred–you studied mathematics? That’s really awesome–I’m  
studying grad stat right now.

On Mar 13, 1:44 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
