I'm trying to make changes made by javascript persistent.
Specifically, I have a rails app which allows a user to "like" other users' posts. When the user likes (faves) a post, or when a new favorite is created, I want the background colour of the post to change (say, to green) using javascript and/or jQuery (I could not see any other way to do this). The problem is that when I reload the page the change is not persistent, with the background colour turning into the default one.
I've tried the following, none of which worked;
addClass in combination with removeClass
append the <style> ... </style> tags directly so the changes in styling can be persistent, without success.
I've tried the above both in app/views/favorites/create.js.erb and directly in the view template where faved posts appear using <script> ... </script> tag.
Any suggestions will be greatly appreciated.
favorite(or something like it) to the database when the user likes a post?favoritemodel stored in the database and I use Ajax request to create/destroy the resource. What I wanted was just a client-side logic which could allow modifications made by javascript to be persistent. But since this seems to require a storing of UI data in the db, which you say is not the right approach, I decided not to implement this feature. Could you tell me why it's a bad idea to store UI information in the db?