Problem with Stimulus and counter_culture gem (counter_cache)
Hy all, i have a problem with the counter_culture gem with my stimulus controller.
I have installed the gem and configured all.
I have 3 model :
Thats working fine for this relation: Category have a capsules_count column for counting how many capsules have a category
But i have a problem for counting the number of wishlist each Capsule have:
THE counter increase well in backend but in my frontend ( with stimulus ) i need to refresh the page for having the good value:
Here my models / controller and views !
CAPSULE
class Capsule < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
monetize :price_cents, allow_nil: true
geocoded_by :address
after_validation :geocode
ACCEPTED_CONTENT_TYPES = %w[image/png image/jpeg].freeze
has_many_attached :images
belongs_to :user
belongs_to :category
counter_culture :category, touch: true
has_many :wishlists, dependent: :destroy
has_many :wishlisted_users, through: :wishlists, source: :user, dependent: :destroy
end
WISHLIST
class Wishlist < ApplicationRecord
belongs_to :user
belongs_to :capsule
counter_culture :capsule
end
THE FRONT END
<div class="bg-white flex justify-center items-center rounded-md text-xs p-1" data-controller="wishlist-counter" data-capwishlists="<%= capsule.wishlists_count %>">
<span data-wishlist-counter-target="text"></span>
</div>
THE STIMULUS CONTROLLER
import {Controller} from "@hotwired/stimulus"
// Connects to data-controller="wishlist-counter"
export default class extends Controller {
static targets = ['counter', 'text'];
connect() {
this.textTarget.innerText = this.element.dataset.capwishlists;
}
}
When i click in the like button the value of my wishlists_count upgrade well but i need to refresh the page for stimulus in my front end to show the exact value and i dont know why ^ ^ ?
THE wishlists_count add + 1 value well in back end but the value is not INSTANTLY refreshed in my front end (stimulus) ...
Thanks you for anyone can help me.
Casinos in Europe are often celebrated for their architectural beauty, cultural events, and historic charm, making them destinations beyond gambling. Tourists enjoy concerts, fine dining, and art exhibitions inside these grand venues, which highlight local traditions and hospitality. In Norway, physical casinos are limited, yet the topic of Casino bonuses Norway is frequently discussed in relation to online platforms. Still, the main focus ofte
remains on cultural identity, tourism, and the way entertainment spaces influence community life across different regions.
brainrot games offers an innovative approach to gaming. Are you ready to put your brain to the test?
It’s working correctly on the backend — the counter_culture gem updates the wishlists_count in the DB — but Stimulus is just reading the initial value from the HTML on page load, so it won’t update automatically after an AJAX action unless you explicitly update the DOM value in JS after the request. It's a lot like https://animeflix.city/ Fast Payout Casinos: the backend processes everything quickly and efficiently, but unless the frontend (or the player) sees the updated balance, it feels like nothing has changed. Keeping both in sync is key to a seamless experience!