When doing javascript manipulation of what's visible, how does one pass that from page to page (ideally in Rails)?
For example, let's say I have the following simple jQuery code:
<% link_to "Next Page", report_path %>
<div class="clickable-div" style="background-color:#FFFFFF;"><开发者_C百科/div>
<script>
$('.clickable-div').click(function () {
var color = $(this).css("background-color", "#000000");
});
</script>
If it's not clear, the code is just supposed to change the color of the div based on whether or not it has been clicked. Regardless, there's also a link on the page that allows someone to go to the reporting page. What's a way to pass the state of the div to the action call?
EDIT
It seems unnecessary to do it in a session - am I wrong? This is just something from one page to the next, I couldn't care less anywhere else on the site.
EDIT 2
To confirm, Rails needs to have access to the action that occurred in Javascript on the previous page.
Try passing the params through a hidden field - http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field
Your persistent storage options are session, database (i.e. a preferences table), and cookie.
If you don't want to use session or cookie, the only other option I see is modify the link URL when that div color changes to add a query string parameter with that color.
There is no need if jQuery or Javascript.
Onto the call of that link you can either store background-color in SESSION or COOKIE
精彩评论