quick rails section, say I have two models Users and Roles and I want to create an index/list of Users based on a certain Role, how do I go about building that in my controller
is it something like
#first create the association
@user = role.build
#then build the index based on a Role of role_id = 2
@userrole = @user.where(@user.role_id == 2)
I know this is pseudo code, but is this correct? And what is the proper rails code?
This is just an example because obviously if we already know the ids we wouldn’t need the first query but if our roles had an editable column (as an example) we could do:
And if we wanted to order these we could simply add: