1

Example code:

#model
class Profile < AR:Base
  has_many :projects
end

#controller
class ProfilesController < AC
  def show
    @user = Profile.find(params[:id])
  end
end

#view

@profile.projects.each do |project|
  = render something
end

Any user can view any profile, but projects should be filtered by visibility (like public/private projects).

I'm concerning to add one more ivar because it violates Sandi Metz's rule

Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed).

The only way I see it now is to introduce another class (facade) to do this things, like:

class ProfilePresenter
  def initialize(profile, current_user)
    @profile = profile
    @current_user
  end

  def visible_profiles
    ProjectPolicy::Scope.new(current_user, profile.projects).resolve
  end
end

Am I missing something?

How would one achieve it (resolving association scopes) using Pundit?

In case we will need pagination for projects within profile view - what approach to choose?

Aleksandr K.
  • 1,338
  • 14
  • 21

0 Answers0