Specifying controller action for an action in a route definition

Hi Rails Core Team,

I’ve noticed that you can set the controller method use by a route doing:

resources :assessments, only: [:create], to: :create_asessment_for_company

``

Is this unintended? If this is by design, how can I set the method for each action in the array? I tried something like the following, but it didn’t work.

resources :assessments do member do get ‘result’ end resources :respondents, only: [:new, :create], :new_respondent_for_assessment, to: :create_respondent_for_assessment do collection do post “invite”, to: :invite_all get “invite”, to: :new_invite end end end

``

Is there a way to do this? I’ve looked through the rails guides and the ActiveDispatch docs and couldn’t see a way. Is this a feature, you’d accept a pull request for?

The reason why I’m trying to do this is my actions return JS and I need different JS to run depending on the context of the request aka. Is the respondent being edited in general, or is the action happening in the “scope” of the assessment. I’m trying to use the URL in what I understand is a RESTful way to identify a particular context.

Thanks, Jeff

As far as I remember, you should use the controller option to point the resource to a specific controller. And if you need to customize each action, maybe you’re not creating a resource at all, maybe you need to review what resource(s) you are working with.

Hope that helps :slight_smile: