I'm working with Hotwire the last month or two and trying to understand how to reload a specific turbo-frame after it renders the first time.
Let's say I have a simple rails controller for user searches. If it has a param of name
, return users matching that name
, if not, return all users.
class UserSearchController
def show
return User.where(name: params[:name]) if params[:name].present?
return User.all
end
end
I have a Turboframe hooked up that is correctly lazy loading all users in the DOM. What I'm trying to figure out is how I can update that Turboframe and redraw the frame. I've played around a bit with Stimulus and trying to set the src to the endpoint, that's the suggestions I've seen in other posts:
reload() {
const {src: src} = this;
this.src = null;
this.src = src;
}
That doesn't seem to work though, it doesn't redraw the turboframe. I can see it's making the request though to the rails backend.
Would anyone be able to point me in the direction of reloading/redrawing a frame after a page loads? I'm not sure if I'm completely off or am in the right ballpark.