Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

309
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!