The show
method for a user's profile page uses typical pundit policies to display/hide user-specific actions (such as editing) based on whether the page owner is signed in.
So the show view for example contains:
- if policy(@user).edit?
= link_to "Edit Profile", edit_user_path(@user)
I'd also like to add a link that shows the signed-in user in a new tab what the page would look like to a public user (not signed in), ideally without creating a whole new view, perhaps something adding a 'public' url param to the show url, like
- if policy(@user).edit?
= link_to "Show Public Version", user_path(@user, public_view: 'yes'), target: "_blank"
Of course it's easy to brute-force by changing all the policy-based logic in the view from
- if policy(@user).edit?
to
- if policy(@user).edit? && !@public_view
(where @public_view is set true in the controller when params[:public] == 'yes')
But I expect there is a much DRYer and cleaner approach, perhaps some modification to the actual UserPolicy methods?