I know this is an old topic already answered, but as I see there is no explanation for why the code of @Зелёный works and not that of @sonalkr132 (I know this can seem off-topic, but @sonalkr132 posted another question which showed me that he didn't understand how it works)
When you create nested resources like projects
inside users
, rails you risk to have a path like users/:id/projects/:id
, which is nonsense, so rails automatically adds a prefix to the first :id
, and thus in params
you have :user_id
and :id
(referencing to :project_id
, but no doubt we are in the ProjectsController, so no further clarification is needed)
Now, when you say param: :user_id
, this adds together with the prefix user_
, that is why you get :user_user_id
- you ask rails do the job twice.