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

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:

<h1>Editing article</h1>

<% 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?

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.

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

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.