Reputation: 2293
Inside of a view in my rails app. I am trying to detect the screen size using JavaScript and render some rails content depending on the screen size.
Here is what I have:
<script>
if( $(window).width() < 1000){
'<%= @resize = true %>';
} else {
'<%= @resize = false %>';
}
</script>
I keep getting false returned for the @resize variable even if the browser window size is less than 1000. How would I go about getting this to work?
Upvotes: 0
Views: 135
Reputation: 19879
You need to change things up:
Note the problem with this approach is that on the very first page load Rails won't have access to that cookie data. Only on the next request will it get the value. But there's no way around that.
Upvotes: 1