[Rails] Re: Roles that are User<>Project Based
All,
I got this working, but would love to know if this is the way to do it
RIGHT with Rails 3?
@teammembers = @project.users.joins(:permissions
=> :role).select("roles.name")
thank you!
On Sep 17, 5:14 pm, nobosh <bhellm...@gmail.com> wrote:
> Alright Marnen, I think I'm getting it... I was able to get the team
> members by using the following in the projects controller:
>
> @teammembers = @project.users
>
> That gives me the users, but it doesn't provide the user's roles. I
> tried including/joining roles to the code above but that errored. Any
> tips?
>
> On Sep 17, 3:27 pm, nobosh <bhellm...@gmail.com> wrote:
>
>
>
> > Thanks Marnen, obviously it hasn't clicked yet but I'll get it! Am I
> > at least right trying to get this to work as a Scope in the Project's
> > model, so I can have the controller pass the team members array to the
> > Controller to the view projects> show.html.erb?
>
> > Thanks
>
> > On Sep 17, 3:22 pm, Marnen Laibow-Koser <li...@ruby-forum.com> wrote:
>
> > > nobosh wrote:
> > > > Continuing along this thread... I'm interested in creating a SCOPE in
> > > > the project model (project.rb) that returns all the project's members
> > > > (bassed on the permissions table <> users & role tables.
>
> > > > Desired output:
> > > > user.name, role.name
>
> > > > Here's my scope in the model, which isn't returning the desired
> > > > output:
>
> > > > class Project < ActiveRecord::Base
> > > > has_many :permissions
> > > > has_many :users, :through => :permissions
> > > > #Playing with Scopes
>
> > > > scope :teammembers,
> > > > Project.permissions.joins(:users, :roles)
>
> > > > end
>
> > > > trying to figure out how to get the output with ActiveRecord. Thanks
>
> > > You're making the exact same mistake as before. Project.permissions
> > > just returns an array of Permission objects.
>
> > > Best,
> > > --
> > > Marnen Laibow-Koserhttp://www.marnen.org
> > > mar...@marnen.org
>
> > > 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home