Better way to phrase the question... Given the model above,

Knowing the project_id and user_id, how in Rails using activemodel can
you query to obtain the user's role if any,,, meaning return admin or
nil

I'm trying things like in the users.rb:
logger.debug self.permissions.find_by_project_id(1)

But that doesn't give back a role... Tricky stuff!!!


On Sep 15, 1:51 pm, nobosh <[email protected]> wrote:
> Thanks Marnen, that's the kind of info I needed as a newbie. I ended
> up rolling back and calling it: ProjectPermissions
>
> The last high-level puzzle piece is in CanCan where it determines what
> permission is granted, with the bitmask method it looks like:
>
> if user.admin_for_project?(project)
>   can :manage, :all
> else
>   can :read, :all
> end
>
> Given the Y relationship we created, in Rails how to you put that into
> the IF statement above?
>
> ***
> if user.permissions.role.find(admin)?(current_project)
> ***
>
> And I'd be passing the current_project variable from the
> application_controller...
>
> Thanks,
>
> Brett
>
> On Sep 14, 10:06 pm, Marnen Laibow-Koser <[email protected]> wrote:
>
>
>
>
>
> > nobosh wrote:
> > > Marnen, in your example models above, permissions is the name of the
> > > table correct? that I create?
>
> > Yes.
>
> > > I ended up calling it: projects_users_roles
>
> > That's not a good name.  If your table needs a model (as here), then you
> > should take the time to find a descriptive name for it -- which is why I
> > used Permission.
>
> > Best,
> > -- 
> > Marnen Laibow-Koserhttp://www.marnen.org
> > [email protected]
>
> > Sent from my iPhone
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> On Sep 14, 10:06 pm, Marnen Laibow-Koser <[email protected]> wrote:
>
>
>
> > nobosh wrote:
> > > Marnen, in your example models above, permissions is the name of the
> > > table correct? that I create?
>
> > Yes.
>
> > > I ended up calling it: projects_users_roles
>
> > That's not a good name.  If your table needs a model (as here), then you
> > should take the time to find a descriptive name for it -- which is why I
> > used Permission.
>
> > Best,
> > -- 
> > Marnen Laibow-Koserhttp://www.marnen.org
> > [email protected]
>
> > Sent from my iPhone
> > --
> > Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to