Hello!
I need some help on something that seems very basic and ‘noobish’ to
me but that I cant figure out…
I’m going to try to make it as simple as possible…
I have a method that initializes an array. Let’s call it "main_view’.
Why? Because it is the main view.
The corresponding view - main_view.rhtml - does not do anything with
this array, instead, it contains links to ajax-powered partials that
let users alter this array in different ways, depending on what link
they click on.
If my page was made in ascii-‘art’ and I had a 2 minutes deadline, it
would probably look as bad as this:
Add elements
Remove elements
Swap elements
Partial to
let user
alter the array
So, when I click on a link, it goes to, for example, an “add_element”
method and loads the partial.
Then I edit/alter/… the array, + all those things users have to do.
Then, once i am done, it goes to an “update_array” method that gets
the data from the partial and updates the array with it.
Now, the big problem i am facing :
I cannot find how to cleanly and elegantly pass the array from my
‘main_view’ method to the ‘add_element’ (or other), then to the
‘update’ method and finally back to ‘main_view’ for another round of
modifications.
I could probably pass it like this, using hidden fields or whatever
comes to my mind :
main_view method => main_view.rhtml
user clicks on add element => add_element method =>
_add_element.rhtml
user updates the array from the view and clicks on update => update
method => main_view.rhtml => …
But just thinking about how ugly it is is gonna make me have
nightmares tonight.
Or… I could make this array a sessions variable, but it’s not clean
either as it might stay in the session variable for ever… And i dont
want dust on my variables.
So, is there any nice way of doing this? Am i missing something here,
some part of Rails’ magic?
Any help would be greatly appreciated, I am kinda tired and dont want
to have nightmares tonight
Thank you!
Gedeon