Hey I was wondering if anyone knows of a gem or plugin that can limit
fields returned based on the User’s role? I’m looking for something
that will basically rewrite the find() method to limit the fields
returned based on the User role.
Hey I was wondering if anyone knows of a gem or plugin that can limit
fields returned based on the User’s role? I’m looking for something
that will basically rewrite the find() method to limit the fields
returned based on the User role.
To store the visitor in the Thread, the simplest solution is:
unless Thread.current.respond_to?(:visitor)
class << Thread.current
attr_accessor :visitor
end
end
Thread.current.visitor = logged_in_user
Gaspard
Thanks! I’ve been looking through the code and like what I see. I think
I may end up with my own unique implementation, but it’s helpful to see
how others have done things.
Gaspard, I noticed your program uses scopes to limit the returned
information. I’m running rails 2.3.4 and there seems to be an issue
with scopes and HABTM relationships: that they don’t carry through.
I’ve tried using named scopes in my Product class like this:
class Product < ActiveRecord::Base
has_and_belongs_to_many :categories
named_scope :with_fields_for_role, lambda {|role| {:select => code
to only select certain columns based on role } }
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products
end