I cannot restrict the Project model view to a owning user. Cannot figure this one out:
Error:
undefined method `user' for #<Project::ActiveRecord_Relation:0x007f94b25dd010>
project_policy.rb
class ProjectPolicy < ApplicationPolicy
def show?
user.present? && user == record.user
end
end
Projects controller
class ProjectsController < ApplicationController
def show
@project = Project.find(params[:id])
@pages = @project.pages
authorize @projects
end
If I remove the user == record.user
all works fine
application_policy
file is default
Project belongs to User User has many Projects
project.user
in the console works fine.