Christian Whitesides


880 Experience
8 Lessons Completed
0 Questions Solved


🎉 Thanks so much, Chris!

That looks much nicer. Thanks for the tip! And thanks again for taking the time to respond. I really appreciate it.

Thanks, Chris! Just what I needed. Each tab is tied to an individual controller (in order to avoid writing custom actions), so I just created the following helper:

def index_based_on_controller(controller)
    case controller
    when "user_books"
    when "user_books/want_to_read"
    when "user_books/reading_now"
    when "user_books/finished"
    when "user_books/recommended"
    when "user_books/dropped"

Then I used the helper in my div with the navigation, like so:

<div data-controller="filter-statuses" data-filter-statuses-index="<%= index_based_on_controller(params[:controller]) %>" >

Worked out great! If there's a better way to write the helper above, please let me know. Once again, thanks for your help!

I have a version of your Tabs tailwindcss-stimulus component up and running. However, I'm struggling to figure out how to save an active tab so that it remains active after a page reload. Right now a page reload just kicks the nav back to the tab at index zero...

localStorage seems to be the recommended way to go, but the help I find everywhere is strictly jquery-based. If you have any suggestions, I'd appreciate it! 🙏

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.