I have table row shading (for groups of row) via js.
I want to make it so that the shading is remembered through a session variable.
The haml partial I am using has:
Group Shading:
%a{:href => '#', :id => 'row_colors_on'}
On
%a{:href => '#', :id => 'row_colors_off'}
Off
the js has:
$(function(){
$("a#row_colors_on").click(function(){
$(".row_color_group_1").addClass("color_group_1");
$(".row_color_group_2").addClass("color_group_2");
$(".row_color_group_3").addClass("color_group_3");
<%- session.group_shading = 'true' %>
event.preventDefault();
});
});
$(function(){
$("a#row_colors_off").click(function(){
$(".row_color_group_1").removeClass("color_group_1");
$(".row_color_group_2").removeClass("color_group_2");
$(".row_color_group_3").removeClass("color_group_3");
<%- session.group_shading = 'false' %>
});
});
the main page then uses:
- row_bg_color_group = 'row_color_group_1'
- for link in @links
- construct_hyperlink(link.url_address, link.alt_text)
- if link.group.group_name != (current_group ||= '')
- display_group = current_group = link.group.group_name
- row_bg_color_group = rotate_rows_color_group
- else
- display_group = ''
%tr{:class => "#{row_bg_color_group}"}
The code to change the background color of rows does do it but it is not remembered after a page refresh through the session variable ?
with the helper:
def rotate_rows_color_group
if session[:group_shading] == 'true'
cycle('row_color_group_1', 'row_color_group_2', 'row_color_group_3')
else
'row_color_group_1'
end
end
but I always get the 'else' condition, i.e. session[:group_shading]
is not being either set or recognized
The css is
.color_group_1 { background-color: #133333; }
.color_group_2 { background-color: #122222; }
.color_group_3 { background-color: #111111; }