On Lunes, 26 de Julio de 2010 11:58:31 rvhi escribió:
> Hi,
>
> I have read http://wiki.github.com/activescaffold/active_scaffold/tips
> and try to apply it in my application. My case is supposed to be easy,
> but I can't figure out how.
>
> class Department < ActiveRecord::Base
>   has_many :employees
> end
> class Employee < ActiveRecord::Base
>   belongs_to: department
> end
>
> Department has a Boolean field web_access. Employee has a field
> web_access, enum (0, 1, 2) where 0 is deny, 1 is allow, 2 will use
> department's web access level. It is pretty straight-forward. There
> are 4 combination,
> 1: employee is 0, deny
> 2: employee is 1, allow
> 3: employee is 0 and department is 0, deny
> 4: employee is 0 and department is 1, allow
>
> The objective is to define a method is EmployeesController
> self.condition_for_web_access which does search either allow or deny.
> For example, allow would search employee 1 or employee 2 and
> department 1. Can someone help on this search?
>
> Thanks,

You can add in your controller a class method named 
condition_for_web_access_column and return conditions array for rails' find 
method. Something like this:

def self.condition_for_web_access_column(column, value, like_pattern = nil)
  find_value = value == 'allow' ? 1 : 0
  ['employee = ? OR (employee = 2 AND department = ?)', find_value, find_value]
end

-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to