Keeping an array through action calls

I have a model, “note”, which has any number of tags. I want users to be
able to create tags within the same form as creating a note. I have that
part. :slight_smile:

Where I’m lost is that I want to be able to type in a tag name, hit
enter, and have it added to a temporary list of tags which tracks the
tags that have been added to this note. So you go to write a note, fill
everything out, and type in a tag named, “ruby” the page is reloaded,
and “ruby” is now a saved tag. Type in another name, it’s saved, and
added to the list. Save the model and the list is saved as that models
tags.

I was hoping to do it by initializing a array in my “new” action. Of
course, that doesn’t work because the “create” action has no knowledge
of the variable. However, if I initialize the variable in the “create”
action, it’s set back to [] after I send the form. So the tag is saved,
but there’s no tag list.

Hopefully I got this across successfully. If anything’s unclear, please
ask me to correct it.

Thanks,

Adam

Hi Adam,

This depends on if your creating a new Note, or modifying an existing
one.

If your creating a new Note you could use your session to store the
array in until it’s time to create the Note.

When you display your form for the first time, set the value in the
session to nil, then add the tags as the are submitted. When the time
comes to create the Note, add the tags then.

Or if the Note already exists, just save them to the note object as you
go.

I think perhaps an ajax solution for adding the tags, instead of
re-loading the page when a tag is entered would be nicer.

I hope i’ve understood your issue correctly.

Cheers