I've searched through the hotwire docs and I know that I can pass target value to "_top" to make full page reload. But I need some elegant way to do this. Let's say i have on the every page selectbox where user can pick account under which he will work within the system. Selectbox returning as a value account id. So my endpoints are nested under accounts eg. /accounts/:account_id/some_path
...
Now let's say user is on the /accounts/5/some_path
and then pick from the select box account with id 4
. Now what I want to achieve is that user will remain on the current page just need to update account id in url and the whole content of the current page. Is there a way to do this with hotwire?
Note: some_path
can be every endpoint nested under accounts
Note2: in selectbox is also option to create new account which can access accounts/new endpoint
<%= form_with(model: user, local: true) do |form| %>
<%= form.select(:account_id, user.accounts.collect { |p| [p.name, p.id] } + [['New account', 'new']], { :prompt => "Select account" }, onchange: 'location.href=document.getElementById("user_account_id").value') %>
<% end %>
I try this but I think Hotwire is able to do this also... unfortunately I'm newbie with hotwire so appreciate any help...