re: Controller filter parameters

Manfred Stienstra
Tue, 03 Nov 2009 13:40:10 -0000

Hi Rodrigo,

The boolean accessors on the User model could probably be refactored,
but you get the idea.

   class User < ActiveRecord::Base
     has_many :roles

     def institution_admin?
       roles.any? { |r| r.label == ''institution_admin'' }
     end

     def system_admin?
       roles.any? { |r| r.label == ''system_admin'' }
     end
   end

   class InstitutionController
     allow_accesss(:system_admin)
     allow_accesss(:institution_admin) do
       @authenticated.institution == @institution
     end

     prepend_before_filter :find_institution

     private

     def find_institution
       @institution = Institution.find(params[:id])
     end
   end

Can we continue this discussion on Ruby on Rails: Talk? This list is
meant for discussions about Ruby on Rails core development.

Manfred