I have a list of "li" tags and I can hide and show no problem through RJS based on user input but what the data gets saved and then the user comes back the next day, how do I make it so the page comes with the elements still hidden? In other words, based on data in a model, how do I tell an element it should be hidden?
So you're user clicks some stuff or submits something and li items show / hide?
They then leave the site, maybe come up tomorrow or a later date?
I would set a cookie which contains a string of the li items that are to be hidden.
I would have a jquery function that I can pass that string to. In the body of my site I would have a little something like (pseudo code)
if cookie exists {
// echo function in the body tag
echo 'onload="hideItems(' . $_COOKIE['hiddenItems'] . ')";
// so if there's a cookie they'll wind up having code that looks like this
// <body onload="hideItems(12-23-34-52);">
}
You'd want a javascript function that is going to parse those numbers then hide the ones that need to be hidden.
function hideItems(string) {
var partsArray = string.split('-');
// this'll put all your list items in an array
// e.g partsArray[0] == 12 and partsArray[1] == 23
// now with all the items in an array, you should be able to go through and hide any list items that match the values
// e.g
for (i=0; i< {partsArray}.length; i++) {
// jquery hide the list items
$('#listItem'+partsArray[$i]).hide();
}
}
I would imagine then your list items would need to be in a format like this:
<ul>
<li id="listItem12"></li>
<li id="listItem23"></li>
</ul>
So I think thats how you'd do it with javascript.
Of course you could just do it on the server side though before javascript is even loaded and parse that cookie to ruby. If the list items number is contained in the cookie then echo out a hidden class to the list item. Simple.
I don't know ruby so the cookie code I edited out is based off php lingo.
Best of luck. Hope this helps.