Your permission code might be helpful for this.

These types of things where view is dependent on some setting that
isn't available until after the record is saved is typically handled
by adding an early termination on the view permission.

def view_permitted?(attribute)
  return true if new_record?
  ...
end

also, not that this is necessarily helpful for this particular
situation, remember that you can chain permission calls.

def view_permitted?(attribute)
  return false unless parent.viewable_by?(acting_user, attribute) #
need to use viewable when calling to properly set acting_user
  ...
  true
end

On Aug 30, 9:02 am, Dean <[email protected]> wrote:
> I need some help understanding how view_permitted? works with child
> records.
>
> I have a parent record which has many child records.  Whether users
> are only permitted to view the child records is dependent on an
> attribute of the parent record.
>
> The most straight forward way to implement this should be by
> implementing the view_permitted? permission in the child model.
> However this is proving to be more difficult than it should be -
> partly because I'm not understanding what is going on.
>
> When I display the child records view_permitted? gets called a number
> of times.  I was expecting a call with field=nil at the beginning of
> each record and a call for each field with the field parameter set
> accordingly.  This is what happens for the parent record.
>
> However, for the child records the first call to view_permitted? for
> each record has the field parameter set to the index number of the
> record in the set of child records (ie 0 to n).  At the time of the
> first call, the child record model hasn't been populated which makes
> it very difficult to determine if the view should be permitted or not.
>
> Is this the correct behaviour, and if so, how do I get the model
> populated at the first call?
>
> Thanks,
>
> Dean

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to