Ask A Question


You’re not receiving notifications from this thread.

Current_account selection

Stan X asked in General

Hi Guys,

In the app I am building, my users have several accounts (though account_users).
For each account they can create, view, update... articles
I would like to have a global selector at the top to pick the account.
Selecting the account would propagate to views, actions....

  1. I tried the current on rails 5.2
    (Rails 5.2 ActiveSupport CurrentAttributes) described in a screencast but was not sure how to modify the params through a dropdown as this is outside of a model form.

  2. As an alternative to a global current_account (which solution I am not capable of doing right know), I was also thinking of creating an additional attribute for the user model like ’selected_account’ as this might ease for changing through a form. but I can see this might not be the way to go if the link is sent across users.

Also, I wanted to avoid carrying the account id in the url as params unless it is much much simpler (or mandatory). but doing this might be a trouble when you share link between users….so I’ll go for the simplest solution (1, 2 or else).


here is my model setup:
has_many :account_users
has_many :accounts, through: :account_users
has_many :account_users
has_many :users, through: :account_users
belongs_to :account
belongs_to :user


So far, I have applied the Current.account as described in this other episode ( ).

However, not sure how to populate a dropdown idem for shifting this Current.account (meaning to modify script name).

 <select  id="mySelect">
         <% current_user.accounts.order(name: :asc).each do |account| %>
                             <%= link_to(,  params.to_unsafe_h.merge(script_name:>
         <% end %>

the above does not shift anything.

Not sure this is the direction i should take (option 1 in my question above).


I finally went for 1 with Current.account implementation (a few days banging head). it works about ok....I have a lot of workarounds though...closing this. feel free to comment if you need some input. (PS: be part of the community).

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 80,973+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

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

    © 2024 GoRails, LLC. All rights reserved.