Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does rails resource not generate edit and new paths?

I have a PasswordsController to handle password recovery and I want to route it as a singular resource.

The code from the router:

resource :password

I want to use the generated routes as follows:

/password/new    # User enters email
/password/create # Send email with link to password edit form with token
/password/edit   # User edits password
/password/update # Password is changed

But for some reason rails only generates the following routes:

password GET    /password(.:format) passwords#show
         PATCH  /password(.:format) passwords#update
         PUT    /password(.:format) passwords#update
         DELETE /password(.:format) passwords#destroy
         POST   /password(.:format) passwords#create

According to the documentation there should also be an edit path and a new path.

Why are they missing?

(This is rails 5.2.1.1)

Edit: As mentioned in the comments, problem must lie somewhere in my app's configuration as this is not reproducible with a clean rails app.

like image 254
lukad Avatar asked Oct 20 '25 15:10

lukad


1 Answers

It looks like you have an api_only app. In that case Rails omit edit and new path. see: https://github.com/rails/rails/blob/fc5dd0b85189811062c85520fd70de8389b55aeb/actionpack/lib/action_dispatch/routing/mapper.rb#L1230

like image 119
Farson Avatar answered Oct 23 '25 07:10

Farson