D
D
Diesel-nick2016-07-22 08:44:13
JavaScript
Diesel-nick, 2016-07-22 08:44:13

Rails 5 + Bootstrap simple sidebar - how to keep sidebar position (hidden/ not hidden) when switching between pages?

How to make sidebar menu in Rails 5 application with Bootstrap simple sidebar pattern and keep sidebar position (hidden/ not hidden) when switching between application pages?

Tried to use jquery.cookie.js plugin and cookies in coffee, but it doesn't work (menu opens and closes itself when switching pages):
sidebar.coffee

# Sidebar togle
$(document).on 'turbolinks:load', ->
  if $.cookie('sidebar_hidden') is 'hidden'
    $('#wrapper').addClass('toggled')
  $('#menu-toggle').click (e) ->
    e.preventDefault()
    # setCookie 'sidebar', 'toggled'
    $('#wrapper').toggleClass 'toggled'
    if $('#wrapper').hasClass('toggled')
      $.cookie 'sidebar_hidden', 'hidden',
        expires: 7
        path: '/'
    else
      $.removeCookie 'sidebar_hidden'
    return
  return


Are there any more correct methods for solving this problem (Rails sessions, Ajax or something else)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question