Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
Rails Javascript issue - Uncaught ReferenceError: filterArticleToggle is not defined

I have a piece of javascript code that is switching between two different views of articles.

When I load the article index page I get the following error:

Uncaught ReferenceError: filterArticleToggle is not defined

I don't know what I have done wrong. I'm using the same code for profile pages and it works fine:

filterArticleToggle = function () {
    const grid_articles_button = document.querySelector('#grid_articles')
    const list_articles_button = document.querySelector('#list_articles')
    const grid_articles_icon = document.querySelector('#grid_articles_icon')
    const list_articles_icon = document.querySelector('#list_articles_icon')
    const grid_articles_view = document.querySelector('#grid_articles_view')
    const list_articles_view = document.querySelector('#list_articles_view')

    if (grid_articles_button && list_articles_button) {
        grid_articles_button.addEventListener('click', (e) => {
            e.preventDefault()

            grid_articles_icon.classList.add('text-brand-blue')
            grid_articles_icon.classList.remove('text-inherit')

            list_articles_icon.classList.remove('text-brand-blue')
            list_articles_icon.classList.add('text-inherit')

            fetch("/articles/switch_view/Grid").then(function(response) {
                return "ok"
            })

            grid_articles_view.classList.value = "sm:-mx-6 lg:-mx-0 flex flex-wrap"
            list_articles_view.classList.value = 'hidden'
        })

        list_articles_button.addEventListener('click', (e) => {
            e.preventDefault()

            grid_articles_icon.classList.remove('text-brand-blue')
            grid_articles_icon.classList.add('text-inherit')

            list_articles_icon.classList.add('text-brand-blue')
            list_articles_icon.classList.remove('text-inherit')

            fetch("/articles/switch_view/List").then(function(response) {
                return "ok"
            })

            list_articles_view.classList.value = "sm:-mx-6 lg:-mx-0 flex flex-wrap"
            grid_articles_view.classList.value = 'hidden'
        })
    }
}

document.addEventListener('turbolinks:load', () => {
    filterArticleToggle()
})

window.filterArticleToggle = filterArticleToggle

This is in an article.js file that is being loaded in as the article index page loads.

Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda