Situation: I have a team model, a user model and a teamate model for the users of a team.
Say I want to have a view that contains the information of a team team/show
and that I wish (to simplify the user’s experience) to add a list of the users, an add user to team and the possibility to remove a user from that team.
To be perfectly restful, I would need a controller (let’s call it Teamates), it would handle the users of a team.
I would have all the CRUD needed.
Is it clean to have the team/show view call the teamates controller for the following actions: adduser, removeuser, listusers.
What I am trying to achieve is less clicks for the users.
In other words, I would like the user to be able to manage the users of a team from the team view instead if requireing him to navigate even further.
I don’t think you need a controller for teamates.
And you really should not have adduser/removeuser/etc actions in your team controller!
You could set up your routes like that:
Then you would have a UsersController in
app/controllers/team_scope/users_controller.rbTo create a new user for a team, you would post to:
/team/1-team-a/usersand it would hit thecreateaction in the UsersController above.When you use
scopein your routes, it does not change the route helpers like withnamespace. Thenewaction would just be accessible vianew_team_user_path(@team).Hum… so yeah, in this case I would have a TeamatesController, and maybe set up my routes like that:
And then you could edit the associations between a team and its players…
Your form would post the users id to
team_teamates_path(team)…But I’m really not sure it’s the best way, I’d have to think about it. This is not really restful as well.