Scaffolds that only show for impersonal accounts
Hey
Chris Oliver
, I could have sworn someone or myself already asked this, but I couldn't find it anywhere:
Is there a preferred way of limiting a scaffolded feature to only be available to impersonal accounts? I'd like to offer group chat to those who are logged into one of their impersonal accounts. There really isn't a reason for that to show up when you are logged into your personal account if you tied Channels to Accounts.
Beyond not showing it in the navbar, would I need to nest my channel resources inside of accounts in routes or something?
Is there a preferred way of limiting a scaffolded feature to only be available to impersonal accounts? I'd like to offer group chat to those who are logged into one of their impersonal accounts. There really isn't a reason for that to show up when you are logged into your personal account if you tied Channels to Accounts.
Beyond not showing it in the navbar, would I need to nest my channel resources inside of accounts in routes or something?
I came back to this, and I was wondering if anyone else could think of anything else I should do besides the following:
app/views/shared/_left_nav.html.erb:
app/views/shared/_left_nav.html.erb:
<%= nav_link_to "Channels", channels_path, class: 'nav-link' unless current_account.personal? %>
app/controllers/channels_controller.rb:
class ChannelsController < ApplicationController ... before_action :require_impersonal_account
... def require_impersonal_account return unless current_account.personal? flash[:alert] = 'This feature is not supported for personal accounts' redirect_back fallback_location: root_path end end
current_account
in a test for integration tests, and I can't get switch_account
to work:class ChannelsControllerTest < ActionDispatch::IntegrationTest setup do @channel = channels(:one) @account = @channel.account @user = @account.owner sign_in @user switch_account(@account) end ... end
My channel fixtures both point their account to
company
who has personal: false
.In my
ChannelController
, I still have:class ChannelsController < ApplicationController before_action :authenticate_user! before_action :require_impersonal_account ... private ... def require_impersonal_account return unless current_account.personal? flash[:alert] = 'Channels are not supported for personal accounts' redirect_back fallback_location: root_path end end
Unfortunately,
current_account
points to the personal account of the signed in user. I also tried setting Current.account = @account
in my tests, but it still seems to not take effect. Any ideas?Notifications
You’re not receiving notifications from this thread.