How do you organize controllers?
Let's have a model User, Question, Answer, and accordingly, the controllers for them. In addition to the standard CRUD operations as well, for example:
- to questions posed by a specific user GET /users/:user_id/questions
- get all the answers of a user GET /users/:user_id/questions/:question_id/answers
- to sign the user in question(mean habtm relationship) — ?
- create a question from a user(let's say Question#create creates the question is not associated with the user) POST /users/:user_id/questions
- edit the question associated with the user (useful in case you need to be sure that the user exists) — PUT /users/:user_id/questions/:id
Important: I know how to make ranting, and no matter how adequate the methods is just an example, no need to delve into logic.
Interested in how you organize the controllers. I see the following options:
Interested in how you organize the controllers. I see the following options:
1. a controller
1.1 and only basic methods (i.e. CRUD) if, for example, for example 1 action — Question#index, in which if there is a parameter user_id is returned questions to the user, and if not, all questions.
example 1 — Question#index
example 2 — Anser#index
example 3 — it is logical to make a separate controller, such as Subscription method create
example 4 — Question#create
example 5 — Questions#update
1.2 for each case your method, ie:
example 1 — Question#questions_by_user,
example 2 — Answer#answers_by_user_and_question,
example 3 — User#subscribe_to_question (?),
example 4 — Question#create_for_user,
example 5 — Question#update_ (?).
If you use this approach, how do you choose names for actions? You can write Question#questions_by_user, Question#questions_by_user_id, Question#by_user, Question#all_by_user
2. many inspectors and only the basic steps, i.e.:
example 1 — User::Question#index (app/controllers/users/questions_controller.rb),
example 2 — User::Question::Answer#index
example 3 — Subscription#create (in my opinion here is also appropriate to create a separate controller)
example 4 — User::Question#create
example 5 — User::Question#update
If you use another approach, please share.